Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Duplicity of lots

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

    Duplicity of lots

    My strategy is a SMA Crossover with an StochRSI. Problem is that when the SMA crosses over, instead of reversing the order, it duplicate the reverse. I'm not sure what is wrong. I just want to have 1 lot reversing when conditions are met. Below is a sample of my strategy:

    if ((SMA(Fast)[0] > SMA(Slow)[0]) && (StochRSI(14)[0] >= 0.8)&& wasLong == false)
    {
    EnterLong(DefaultQuantity,
    "LongSMAEnter");
    wasLong =
    true;
    }


    if ((SMA(Fast)[0] < SMA(Slow)[0])&& wasLong == true)
    {
    ExitLong(
    "ExitLong", "LongSMAEnter");
    wasLong =
    false;
    }


    elseif ((SMA(Fast)[0] < SMA(Slow)[0]) && (StochRSI(14)[0] <= 0.2)&& wasLong == true)
    {
    EnterShort(DefaultQuantity,
    "ShortSMAEnter");
    wasLong =
    false;
    }

    if ((SMA(Fast)[0] > SMA(Slow)[0])&& wasLong == false)
    {
    ExitShort(
    "ExitShort", "ShortSMAEnter");
    wasLong =
    true;
    }

    #2
    Your code is executing as you have written it. You would have to debug this yourself to understand why. I did scan your code and at first glance I don't see the flaw in logic...we don't spend much time debugging user code as part of our support policy.

    I would look at the wasLong variable as an issue. For the most part, you do not need this in NinjaScript since method calls are ignored when applicable. If you call ExitShort() and there is no short position, it would be ignored.
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    635 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    106 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    569 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X