Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninja Script - Target twice as the previous

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Ninja Script - Target twice as the previous

    Hi all,

    Basically, I want a 2:1 risk-reward strategy.
    The stop-loss should be placed in the low of the previous bar (this I already got it).
    Any help for the profit take logic would be appreciated.
    Kind regards,
    Jose


    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((CandlestickPattern1[0] != 0)
    && (GetCurrentAsk(0) > EMA1[0])
    && (RSI1.Avg[0] > 50))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity),"MyLong Entry" + CurrentBar);
    SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);
    SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false);
    }


    }

    #2
    Hello josedaniel,

    Thanks for the post.

    Could you conform for me, what are you trying to do twice as the previous?

    Are you asking for a target which has a price twice the previous high?

    I see you have a target using Percent, are you asking about getting 2%?

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      Yes, I realized the Tittle was misleading once I´ve posted it.
      I want the target to be twice as big as the Stop-loss.
      If SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false); let´s say is 20 ticks. Then Target should be 40 ticks.
      Basically, accomplishing a 2:1 Risk Reward

      PS: "SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);" was just to put something there in the meantime.
      Kind Regards,
      Jose

      Comment


        #4
        Hello josedaniel,

        Thanks for clearing that up.

        To do that you would need to know the difference between the bars in ticks and then you can just use the Ticks mode:

        Code:
        double ticks = (Close[0] - Low[1]) / TickSize;
        Assuming the logic you have is checking for some kind of up trend this should work, if the previous bars low was greater than the close it would end up being a negative number which would not work.

        To get twice the ticks for the target you would use ticks * 2


        One other side note is that the set methods need to be called before the entry to set them up:

        Code:
        SetProfitTarget("MyLongEntry" + CurrentBar, CalculationMode.Percent, 0.01);
        SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[1]), false);
        EnterLong(Convert.ToInt32(DefaultQuantity),"MyLong Entry" + CurrentBar);

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X