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

Reverse Order in Strategy

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

    Reverse Order in Strategy

    I'm trying to carry out this type of operation within a strategy, but it passes the line and doesn't execute. I'm posting the onPositionUpdate part...

    The Position is Long... and i have Order Short


    Code:
    protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition){
    double reverso = averagePrice - 20;
    if(position.MarketPosition == MarketPosition.Long){
    EnterShortStopMarket(1,reverso,"Venda");   // Passed by here
    Print("entrando Vendido agora:"+averagePrice+" Preço médio:"+reverso);
    }
    Print(position.MarketPosition+" "+MarketPosition.Long); // Flat
    }​

    #2
    Hello Rafaelseki,

    Thank you for your post.

    Have you checked if there are any errors appearing on the Log tab of the Control Center?

    To understand why the script is behaving as it is, such as placing orders or not placing orders (or drawing objects or other actions) when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Output from prints will appear in the NinjaScript Output window.
    NT8: New -> NinjaScript Output

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

    Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.
    NT8 —


    It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().

    TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

    Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

    These tools will let you know what happens to the order.

    TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    I'm also including a link to a forum post with further suggestions on debugging a script.


    Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

    I am happy to assist with analyzing the output from prints and TraceOrders.​
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by dweems, Today, 10:42 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by blar58, Today, 10:37 AM
    2 responses
    9 views
    0 likes
    Last Post blar58
    by blar58
     
    Started by gemify, 12-13-2022, 06:10 PM
    48 responses
    3,922 views
    5 likes
    Last Post Jthunders  
    Started by AngelGL, Today, 10:59 AM
    0 responses
    4 views
    0 likes
    Last Post AngelGL
    by AngelGL
     
    Started by philmg, 02-16-2024, 08:45 AM
    3 responses
    37 views
    0 likes
    Last Post philmg
    by philmg
     
    Working...
    X