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

Strategy with MagicTrend indicator

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

    Strategy with MagicTrend indicator

    I created a simple buy/sell strategy with 2 TrendMagic indicator with different multpliers. It works in the realTime trades but my historical trades are not working. I find really hard to see backtest results. Can anyone help me to understand if i'm missing anything?

    Attahing both codes.
    Attached Files

    #2
    Hello gayathri,

    As a heads up, we recommend you remove the try and catch as this can prevent error messages from being logged on the Log tab of the Control Center, which may be indicating the issue causing the behavior.

    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.
    NT7: Tools -> 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 — https://youtu.be/H7aDpWoWUQs?t=2577&...We0Nf&index=14
    NT7 — https://www.youtube.com/watch?v=K8v_...tu.be&t=48m35s

    If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
    NT8 Strategy Builder — https://drive.google.com/open?id=1CC...D4JjJgEIwJKv6L

    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    NT8 — https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s
    NT7 — https://www.youtube.com/watch?v=K8v_...utu.be&t=5m33s

    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.
    https://ninjatrader.com/support/foru...956#post671956

    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.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your immediate reply. Appreciate your help.

      Attached updated script and log output.
      Attached Files

      Comment


        #4
        Hello gayathri,

        The output needs to match the condition and needs to have the comparison operators, so that we can see how the values are being compared.

        For example a proper informative print for the condition

        if (trendMagic1.IsUpTrend && trendMagic2.IsUpTrend)
        {
        if (Position.MarketPosition != MarketPosition.Long && lastTrade != TrendDirection.Up)
        {​

        Would be:

        Code:
        Print(string.Format("{0} | trendMagic1.IsUpTrend: {1} && trendMagic2.IsUpTrend: {3} && Position.MarketPosition: {4} != MarketPosition.Long && lastTrade: {5} != TrendDirection.Up", Time[0], trendMagic1.IsUpTrend, trendMagic2.IsUpTrend, Position.MarketPosition, lastTrade));

        That said, I am seeing there are orders being submitted in the TraceOrders output.

        Time: 3/26/2023 4:30:00 PM, trendMagic1: 0, trendMagic2: 0, Position.MarketPosition: Flat, lastTrade: Unknown
        3/26/2023 4:30:00 PM Strategy 'bkScalper/288672468': Entered internal SubmitOrderManaged() method at 3/26/2023 4:30:00 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
        Time: 3/26/2023 4:30:00 PM, value - SHORT​

        3/27/2023 3:30:00 AM Strategy 'bkScalper/288672468': Entered internal SubmitOrderManaged() method at 3/27/2023 3:30:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''
        Time: 3/27/2023 3:30:00 AM, value - LONG​

        3/27/2023 8:30:00 AM Strategy 'bkScalper/288672468': Entered internal SubmitOrderManaged() method at 3/27/2023 8:30:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
        Time: 3/27/2023 8:30:00 AM, value - SHORT​

        3/28/2023 1:30:00 PM Strategy 'bkScalper/288672468': Entered internal SubmitOrderManaged() method at 3/28/2023 1:30:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''
        Time: 3/28/2023 1:30:00 PM, value - LONG​
        Are you unable to see these orders in the Strategy Performance window on the Orders display?

        Is there a specific time you are expecting an order where there is not one?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        32 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        4 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        19 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        6 views
        0 likes
        Last Post cre8able  
        Started by Haiasi, Today, 06:53 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X