In AFL, because Buy is 'True' on 'Buy' signals after entry a 'SellPrice' based on: ValueWhen(Buy, BuyPrice); may not be based on the actual entry price.
I read, that for a correct entry price using a loop is necessary. I have modified a loop I found, [modified loops shown below], and in Exploration the stop shown is correct on the entry day. However, as in AFL the stop changes with each new buy signal. I have tried two variations of the location of the Array Subscript Operator. Could someone correct one of these loops to produce the actual BuyPrice plus or minus a fixed amount? Thank you, DirectAim //===XIT================================================ ATRDy= ATR(14); CrshStpMult= 1; TargMult= 1; //XIT LOOP 1 FOR LNGS=================================== BuyPrice= C; Sell= 0; TargLvlLng= 0; CrshStpLvlLng= 0; TargLvlLngARRAY= Null; CrshStpLvlLngARRAY= Null; //XIT LOOP FOR LNGS for(i=1; i<BarCount; i++) { if(TargLvlLng== 0 AND CrshStpLvlLng== 0 AND Buy[i]) {TargLvlLng= BuyPrice[i]+ TargMult* ATRDy[i]; CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i];} else Buy[i]= 0; //REMOV XCESS BUY SIGS if( TargLvlLng> 0 AND H[i]> TargLvlLng) {Sell[i]= 1; SellPrice[i]= TargLvlLng; TargLvlLngARRAY[i]= TargLvlLngARRAY[i]; TargLvlLng=0; CrshStpLvlLng=0;} if(CrshStpLvlLng> 0 AND L[i]< CrshStpLvlLng) {Sell[i]= 1; SellPrice[i]= CrshStpLvlLng; CrshStpLvlLngARRAY[i]= CrshStpLvlLng; CrshStpLvlLng= 0; TargLvlLng= 0;} //REAJUST TargLvlLng + CrshStpLvlLng ON EA BAR? if(TargLvlLng> 0) {TargLvlLng= BuyPrice[i]+ TargMult* ATRDy[i]; TargLvlLngARRAY[i]= TargLvlLng;} if(CrshStpLvlLng> 0) {CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i]; CrshStpLvlLngARRAY[i]= CrshStpLvlLng;} } //XIT LOOP 2 FOR LNGS=================================== for(i=1; i<BarCount; i++) { if(TargLvlLng== 0 AND CrshStpLvlLng== 0 AND Buy[i] ) {TargLvlLng= BuyPrice+ TargMult* ATRDy; CrshStpLvlLng= BuyPrice- CrshStpMult* ATRDy;} else Buy[i]= 0; //REMOV XCESS BUY SIGS if( TargLvlLng[i]> 0 AND H[i]> TargLvlLng[i]) {Sell[i]= 1; SellPrice[i]= TargLvlLng[i]; TargLvlLngARRAY[i]= TargLvlLngARRAY[i]; TargLvlLng=0; CrshStpLvlLng=0;} if(CrshStpLvlLng[i]> 0 AND L[i]< CrshStpLvlLng[i]) {Sell[i]= 1; SellPrice[i]= CrshStpLvlLng[i]; CrshStpLvlLngARRAY[i]= CrshStpLvlLng[i]; CrshStpLvlLng= 0; TargLvlLng= 0;} //REAJUST TargLvlLng + CrshStpLvlLngON EA BAR? if(TargLvlLng[i]> 0) {TargLvlLng= BuyPrice[i]+ TargMult* ATRDy[i]; TargLvlLngARRAY[i]= TargLvlLng;} if(CrshStpLvlLng[i]> 0) {CrshStpLvlLng= BuyPrice[i]- CrshStpMult* ATRDy[i]; CrshStpLvlLngARRAY[i]= CrshStpLvlLng;} }