Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Setting Stop Loss between VWAP and LOD

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

    Setting Stop Loss between VWAP and LOD

    I am trying to make a long order and set the stop at 1/3 the way between VWAP and LOD.
    It compiles fine , but I get Error on calling 'OnStateChange' method Object: reference not set to an instance of an object.
    Here is the code that I think is the issue

    EMA1 = EMA(Close, 9);
    VWAP1 = VWAP(Close);
    VWAP2 = VWAP(Close);
    CurrentDayOHL1 = CurrentDayOHL(Close);
    Stopticks =(int)((VWAP2.PlotVWAP[0] - CurrentDayOHL1.CurrentLow[0])/3);
    BarCounter1 = BarCounter(Close, true, Brushes.Gray, 14, 50, true);
    SetStopLoss(@"Long",CalculationMode.Ticks, Stopticks, false);
    SetProfitTarget(@"Long", CalculationMode.Ticks, Stopticks);

    #2
    Hello BrJessey,

    Thanks for your post.

    "Error on calling 'OnStateChange' method Object: reference not set to an instance of an object."

    This error indicates that something you are accessing in the script is not defined at the time you are accessing it.

    In the code you shared, this is not the correct VWAP syntax for defining a VWAP indicator. The VWAP syntax is noted in the help guide and can be seen below.

    OrderFlowVWAP(VWAPResolution resolution, TradingHours tradingHoursInstance, VWAPStandardDeviations numStandardDeviations, double sD1Multiplier, double sD2Multiplier, double sD3Multiplier)

    See this help guide page for more information on accessing Order Flow VWAP values and sample code: https://ninjatrader.com/support/help...flow_vwap2.htm

    Further, indicator values should be accessed in OnBarUpdate(). You could consider setting up your Stopticks calculation in OnBarUpdate() and then use Exit methods in OnBarUpdate() for your stop loss and profit target orders.

    Attached is a simple example script demonstrating using Exit methods for stop loss and profit target orders which you might find helpful.

    Managed Approach: https://ninjatrader.com/support/help...d_approach.htm
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    16 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    4 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,785 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X