I have a simple system to buy say macd > signal line and then using an ATR trailing stop loss
my problem is when i get multiple buy signals (on same stock; back to back), every 2nd signal is shown as a sell instead of adding to position. so if a stock has 2 buy signals before a big run up, i miss the entire run up cause the 2nd buy was treated as a sell.
I would like to add to the position on every buy signal and keep using the the SL highest since buy - (atr x 2) since the latest buy date.
i would really appreciate if someone could help with this last leg to complete my code.
sample code
//Initial Parameters
SetTradeDelays( 1,1,1,1);
SetOption("InitialEquity", 1000000);
SetOption("MaxOpenPositions", 35 ); // no of open positions //
SetOption( "UsePrevBarEquityForPosSizing", 1 ); //*set the use of last bars
SetOption("MinShares",1); // min no of shares to purchase //
RiskPerShare = 3 * ATR( 14 ); //Risk Per share //
PositionRisk = 5; // risk 5% of entire equity on single trade //
PctSize = PositionRisk * BuyPrice / RiskPerShare; // position size calculation - no of shares//
SetPositionSize( PctSize, spsPercentOfEquity ); //set position size)
SetOption( "AllowPositionShrinking", True ); // Shrink Position on Loss //
RoundLotSize = 1; // Lot Size //
SetOption("CommissionMode", 1); // comms mode
SetOption("CommissionAmount",0.15); // comms rate in %
SetOption("RefreshWhenCompleted",True); // Refresh when completed //
BuyPrice=Open;
Totalpositions = 35;
SetOption("MaxOpenPositions", Totalpositions );
Buy = "some buy parameters"
Sell = 0;
ApplyStop( stopTypeTrailing, stopModePoint, RiskPerShare, 2, True, 0);
/* Plotting the Trailing Stop */
Equity (1,0);
inTrade = Flip(Buy, Sell); //True when Buy, False when Sell
SetOption("EveryBarNullCheck", True); // checks for null bars
stopline = IIf(intrade, HighestSince(Buy, H - RiskPerShare), Null);
thanks,
Gautam