Ninja Trader Ninja Script HELP!

Discussion in 'Programming' started by julian0625, Nov 29, 2011.

  1. Hello,

    I recently wrote a strategy that is a counter trend strategy so it looses money when markets are trending hard.

    I would like my strategy to stop long / short trades from being re-entered if the prior long / short trade resulted in a loss, but I don't know how to program it into ninja script, as I am used to easy language.

    So basically if the last trade was a long trade and it got stopped, I want my strategy to only look for short trades to enter, but once again, I do not know how to program it!

    So please, if anyone could help me I would really appreciate it!!!

    Thanks guys!

  2. anukoti



    One simple way to do it is keep track of the TradeSignal in a variable and until a reverse signal is generated don't take any more trades.

    So, you would do something like:

    PreviousSignal = "None"
    CurremtSignal = "None"

    If LongSignalGenerated {
    PrevSignal = CurrentSignal;
    CurrentSignal = "Long"

    If ShortSignalGenerated {
    PrevSignal = CurrentSignal;
    CurrentSignal = "Short"

    TakeTradeOnly if (PrevSignal <> CurrentSignal)

    This above condition will keep you out of taking trades in the same direction whether Long or Short.

    Hope this helps.