NexusFi: Find Your Edge


Home Menu

 





Disable/Rest Strategy


Discussion in NinjaTrader

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




 
Search this Thread

Disable/Rest Strategy

  #1 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1

I have searched for the life cycle of NinjaScript for NT7 but I wasn't able to find it. I have a strategy that I don't want to over trade, so I will be enabling my strategy and it will activate an ATMStrategy. For now what I have

private bool tradeAgain = true;

protected override void OnBarUpdate()
{

if(tradeAgain)
{

// programming logic

}

tradeAgain = false;

}

After the trade, whether its profit or loss, I want to be able to make the variable tradeAgain = true.

I am wondering if I disable the strategy, and then enable it again, will variable tradeAgain be true or false?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,148


If you want to trade or not trade based on if your last trade was a profit or not you will need something like this.



// In order to run this, you have to call the method below to check and make sure there is at least one trade in the
// collection otherwise it will just error out.

if (Performance.RealtimeTrades.Count > 1)
{

// get variables to hold information about the last trade

Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;

// Run condition to check if the last trade was profitable or not
if(lastProfit > 0)
{
// last trade was a winner do something
}

if (lastProfit <0)
{
// last trade was a loser do something
}


}


In terms of disabling or enabling your strategy, you can do something inside of the code blocks I have provided. There are a number of easy way to tell it to trade or not trade.

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1


iantg View Post
If you want to trade or not trade based on if your last trade was a profit or not you will need something like this.



// In order to run this, you have to call the method below to check and make sure there is at least one trade in the
// collection otherwise it will just error out.

if (Performance.RealtimeTrades.Count > 1)
{

// get variables to hold information about the last trade

Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;

// Run condition to check if the last trade was profitable or not
if(lastProfit > 0)
{
// last trade was a winner do something
}

if (lastProfit <0)
{
// last trade was a loser do something
}


}


In terms of disabling or enabling your strategy, you can do something inside of the code blocks I have provided. There are a number of easy way to tell it to trade or not trade.


Thanks. Will this be for each script or will it take into account all the trades? I need it to run separately on each script. And if lastprofit > 0, simple return will suffice?

Started this thread Reply With Quote
  #5 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,148

The way the code works it is only looking at the last trade.
The variable lastTrade is indexed to -1 which means it will always look at the last trade. You can add a new variable called twotradesago and index it to -2, and do threetradesago with -3, etc. Each of these would be a different trade variable and you would have to extract the p&l stats the same way.

VariableName.ProfitCurrency for example. But I think if all you are looking for is the last trade then go with the -1 index and you have it.

Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 venichhe 
Brooklyn + New York/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: NQ, YM, 6E
Posts: 6 since Dec 2017
Thanks Given: 4
Thanks Received: 1


iantg View Post
The way the code works it is only looking at the last trade.
The variable lastTrade is indexed to -1 which means it will always look at the last trade. You can add a new variable called twotradesago and index it to -2, and do threetradesago with -3, etc. Each of these would be a different trade variable and you would have to extract the p&l stats the same way.

VariableName.ProfitCurrency for example. But I think if all you are looking for is the last trade then go with the -1 index and you have it.

Thank you very much!

Started this thread Reply With Quote




Last Updated on December 13, 2017


© 2024 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 - Privacy Policy - Downloads - Top
no new posts