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 ATM Reversal

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

    Strategy ATM Reversal

    Hi everyone,

    I was wondering if anyone can help me modify a strategy sample uploaded by PatrickH called SampleATMReversal, which I have modified with my own triggers and variables.

    I'm trying to get some more ideas on how to get the strategy to enter based on "entries per direction" specified in my strategy while calling upon an ATM strategy per each entry. Currently, the strategy enters only one time and calls upon the ATM strategy specified but the strategy will not initiate additional entries in the direction of the trigger.

    ChelseaB has already recommended I look into making an array to accomplish and I would just like some more ideas before I ultimately decide how I should go about doing this.

    Here is a portion of the code of PatrickH's code which initiates a long entry and calls upon an ATM strategy.

    Code:
    // Entries.
    			// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
    			// Enter long if Close is greater than Open.
    			if(Close[0] > Open[0])
    			{
    				// If there is a short ATM Strategy running close it.
    				if(shortAtmId.Length != 0 && isAtmStrategyCreated)
    				{
    					AtmStrategyClose(shortAtmId);
    					isAtmStrategyCreated = false;
    				}
    				// Ensure no other long ATM Strategy is running.
    				if(longOrderId.Length == 0 && longAtmId.Length == 0 && !isAtmStrategyCreated)
    				{
    					longOrderId = GetAtmStrategyUniqueId();
    					longAtmId = GetAtmStrategyUniqueId();
    					AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, longOrderId, "AtmStrategyTemplate", longAtmId, (atmCallbackErrorCode, atmCallBackId) => { 
    						//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
    						if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId) 
    							isAtmStrategyCreated = true;
    					});
    				}
    			}
    Here is the link to the strategy file by PatrickH:


    #2
    Hello Rogue_Two,

    Thanks for your post.

    When scaling the logic up, it will be beneficial to add prints to understand why the logic is only allowing one entry at a time so you can best determine how to modify the logic further for your own needs.

    Looking at your segment of code, I see that you are checking the bool isAtmStrategyCreated before calling AtmStrategyCreate(). This bool is set to be true after entering and prevents additional Atm Strategies from being submitted. You may wish to use an integer instead, and to increment that integer for every Atm Strategy entry. When the count meets your EntriesPerDirection property, you can then prevent further Atm Strategies from submitting. When Atm Strategies close, you can decrement the counter.

    As a rough example:
    Code:
    if (AtmEntryCount < EntriesPerDirection)
        //Your entry logic
    I've included a link for our tips on debugging and using prints which can be provide great help for checking your logic and understanding what changes need to be made.

    Debugging - https://ninjatrader.com/support/help...script_cod.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    22 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    16 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    6 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X