I wrote the code below and the issue I am having is that because I didn't know how to adjust 'apply stop' when pyramiding in I added into my for loop as a sell signal, however I want to sell as soon as it hit's stop signal rather then at close.
So I was hoping someone can help me with how to move up my stop signal when I scale in if I use 'applystop()'?
and/or how to set the sell signals, only for when it 'hits my stop' to, the stop level rather then close?
I have included code below (I tried to cut it down to relevant parts so hopefully make sense, and hopefully shouldn't need to go through with explanation)
Thanks for any help!
_SECTION_BEGIN("");
//initialise vaiables
//...
N=ATR(20);
stop=2*N;
//system buy and sell logic
for( i = 20; i < barcount; i++ ) //loop through all bars to check when signals occur
{
if(bx==0) //if there has been a sell signal since last buy
{
//if buy logic { b1=1 bx=1 sx=0 }
}
else If(sx==0) //if there has been a buy signal since last sell
{
if(L[i]<(b2-stop[i])) //stop level 2N below entry price
{
s1[i]=1; //need to reset this so stop is at 'b2-stop[i]' not close price
}
else
{
//if sell logic { s1=1 sx=1 bx=0 }
//else
if((C[i]>b2+N[i]/2)AND(count<3)) //pirimid into position if close is 1/2 N above previous buy in, a maximum of 3 times
{
ScaleIn[i]=1; //scale into trade (add an additional unit)
b2=b2+N[i]/2; //moves current 'buy in'(and thus stop) up 1/2 N
count++;
}
}
}
}
Buy=IIf(b1 , 1, IIf(ScaleIn, sigScaleIn, 0));
Sell=s1;
///what price to buy
BuyPrice=C;
SellPrice=C;
//positon size
unit=Equity(0)*.01/N;
EPS1 = Unit; // Size for first entry
EPS2 = Unit; // Size for 'scalein' entries
PosSize = (b1 * EPS1) + (scalein * EPS2); //set position size of b1 signals and scalein signals
SetPositionSize(PosSize, spsShares); //set position size of all buy signals
_SECTION_END();