There are numerous ways to do this, but here is a simple one Buy = C > MA(C, 20); BuyPrice = C;
StopLoss = C < MA(C, 50); ProfitTarget = C > MA(C, 10); Sell = StopLoss OR ProfitTarget; // If we exit due to stop loss take the 50 MA otherwise // by process of elimination we exit at target 10 MA SellPrice = iif(StopLoss, MA(C, 50), MA(C, 10)); This is here so you can learn how to code such rules, but I should point out that your strategy is unrealistic! You are making a rule where if at the END of a bar we are below an MA we should sell at a price ABOVE the close (ie the MA price that price action is now below). Furthermore the MA will not settle to its final value until the bar is finished (since the MA is calculated on closing prices). You should probably set your sell prices to the open of the next bar SellPrice = Ref(O, 1); -hi --- In [email protected], "dralexchambers" <dralexchamb...@...> wrote: > > Hi, > > How would I put together a backtest for the following. My Buy signal is: > > Buy = C>MA(C,20); > > How do I do a multiple sell signal for the following: > > StopLoss is hit is when C < MA(C,50) Stoploss price is MA50. TakeProfit is > when C > MA(C,10), and TP price is MA10. > > I can only see one Sell & Sellprice variable. How do I put both of these > conditions into Sell & Sellprice? > > Thanks, > Alex >
