1

The following is all Javascript EFS which is javascript but adapted to stocks and trading software.

So in following example: high() is simply the High of price in a 1 minute bar. All bars process a High and Low (price for that minute) every minute.

Okay i have figured out how to use loops. However, i am having difficulty in accessing values within the loop i created e.g.

var Source2 = high();
 var vValue2   = Source2.getValue(15);

for (h = -15; h < 0; h++)       {  
     vValue2 = Math.max(vValue2, Source2.getValue(-h)); 

 if (vValue2 == Source2.getValue(-h))        { 
        barIndex2 = getCurrentBarIndex()-h; 
       }
}

Now lets assume this is all fine and it returns me the values (in this case the Highest high looking forward 15 bars from entry point). However, i now wish to make conditions for the loop to process (all for backtesting purposes) such as:

  • I want to return (vValue2 +1) e.g. 'vValue2' has been returned as the highest high (15 bars) and now i want to know the value of 'vValue2 +1 bar' even if this is not the highest bar.
  • Is there a way for the loop only to return values if multiple conditions are met such as: i. Return the first Highest high of the 15 bars (lets say 'h') IF the bar ('h' +1) of this return value has a LOW which is less than the LOW of ('h') && ('h'+2), ('h'+3), ('h'+4), all have High less than ('h').

Basically i want to add multiple IF conditions to start a loop?? Or am i supposed to add the IF conditions after a loop has returned its values???

  • I am not sure if the things i require are possible or must i use loop after loop to get the desired results.

1 Answer 1

1

You can use multiple conditions in your for loop like this:

for (h = -15; (h < 0 && something == somethingElse); h++)

You can also break out of a loop with something like this:

for (h = -15; h < 0; h++)       { 
    if(blah == 1)break;  // breaks out of loop completely
}
Sign up to request clarification or add additional context in comments.

2 Comments

So can i reference the value h+1 in as a condition?? So something like this would work: (h=-15; (h<0 && (h+1(low)<h); h++. I dont think this will work in my example because first i need to find the Value (Low) of (vValue2 +1) then this must be compared at each count in the loop. The loop would not know what the value of (h+1(low) is until the loop returns vValue2????
The condition part of the for loop is evaluated each time the loop runs. I'm not sure what your low function is doing, but here is an example of how you could have multiple conditions in the for jsfiddle.net/4Sn6q

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.