NexusFi: Find Your Edge


Home Menu

 





Atm strategy help


Discussion in NinjaTrader

Updated
    1. trending_up 2,732 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 darkmarine 
NEW BRUNSWICK
 
Experience: Intermediate
Platform: ninjatrader
Trading: nq
Posts: 11 since Jun 2020
Thanks Given: 2
Thanks Received: 0

below is a atm strategy that i want to build but i dont know why is not working how is suppose to





protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;

if(State == State.Historical)
return;


if (orderIdL.Length == 0 &&
atmStrategyIdL.Length == 0
&& (Stochastics1.K[0] < 20)



{
isAtmStrategyCreatedL = false;
atmStrategyIdL = GetAtmStrategyUniqueId();
orderIdL = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, Low[0], 0, TimeInForce.Day, orderIdL, "ES-LONG", atmStrategyIdL, (atmCallbackErrorCode, atmCallBackId) => {

if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyIdL)
isAtmStrategyCreatedL = true;
});



}
if (orderIdS.Length == 0 &&
atmStrategyIdS.Length == 0
&& (Stochastics1.K[0] > 80)

{
CandleOutlineBrush = Brushes.Crimson;
BarBrush = Brushes.Crimson;
}
{
isAtmStrategyCreatedS = false;
atmStrategyIdS = GetAtmStrategyUniqueId();
orderIdS = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Market, Low[0], 0, TimeInForce.Day, orderIdS, "ES-SHORT", atmStrategyIdS, (atmCallbackErrorCode, atmCallBackId) => {

if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyIdS)
isAtmStrategyCreatedS = true;
});
}

if (!isAtmStrategyCreatedS)
return;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (orderIdL.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdL);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);

// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdL = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyIdL.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdL) == Cbi.MarketPosition.Flat)
atmStrategyIdL = string.Empty;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (orderIdS.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderIdS);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);

// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderIdS = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyIdS.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyIdS) == Cbi.MarketPosition.Flat)
atmStrategyIdS = string.Empty;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (atmStrategyIdL.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyIdL) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyIdL);

// Print some information about the strategy to the output window, please note you access the ATM strategy specific position object here
// the ATM would run self contained and would not have an impact on your NinjaScript strategy position and PnL
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyIdL));
Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyIdL));
Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyIdL));
Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyIdL));

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (atmStrategyIdS.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyIdS) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyIdS);

// Print some information about the strategy to the output window, please note you access the ATM strategy specific position object here
// the ATM would run self contained and would not have an impact on your NinjaScript strategy position and PnL
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyIdS));
Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyIdS));
Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyIdS));
Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyIdS));
}
}
}
}}


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
Thanks Mike. Godspeed.
The Elite Circle
Daytrading to swingtrading
Traders Hideout
Would a node-based workflow for automated trading be useful?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 thanks
  #2 (permalink)
 darkmarine 
NEW BRUNSWICK
 
Experience: Intermediate
Platform: ninjatrader
Trading: nq
Posts: 11 since Jun 2020
Thanks Given: 2
Thanks Received: 0

Could anybody tell me what I am doing wrong


Started this thread Reply With Quote
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,586


What is the error message?

darkmarine View Post
Could anybody tell me what I am doing wrong

Sent using the NexusFi mobile app




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 darkmarine 
NEW BRUNSWICK
 
Experience: Intermediate
Platform: ninjatrader
Trading: nq
Posts: 11 since Jun 2020
Thanks Given: 2
Thanks Received: 0


Big Mike View Post
What is the error message?


Sent using the NexusFi mobile app

Suppose to but when is under 20 and go short when is above 80 but will buy all the time and will never go short


Started this thread Reply With Quote
  #5 (permalink)
Wickwor
Sydney Australia
 
Posts: 1 since Aug 2020
Thanks Given: 1
Thanks Received: 0


darkmarine View Post
Suppose to but when is under 20 and go short when is above 80 but will buy all the time and will never go short

It does this because both of your ATM Create orders are Buy

AtmStrategyCreate(OrderAction.Buy

One needs to be a Sell


Reply With Quote




Last Updated on August 9, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts