Tracking wins, and losses
After every order only one is shown.
2014.05.31 04:41:49 Core 1 2014.05.28 00:00:00 Wins Value :1.0
2014.05.31 04:41:50 Core 1 2014.05.29 00:00:00 Wins Value :1.0
The new value should be 2.
Why ?
Is to possible to update a global variable from within the current function?
I've tried multiple variation what am I missing or is there a post, article anything that can lead me into the right direction?
My understanding at this point is that local variables will take preference
and always return 1 and reset to 0 everything the function is called
i would like to increment the global variable so that it displays 2
so that i can use that information in another function.
//--- Scan Closed Trades double ScanClosedTrades() { HistorySelect(0,TimeCurrent()); int returns=0; int a = 0; int b = 0; int deals = HistoryDealsTotal(); ulong ticket = HistoryDealGetTicket(deals-1); double profit = 0; if(ticket>0) { long order_magic=HistoryDealGetInteger(ticket,DEAL_MAGIC); profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); a++; if (profit < 0) Print("Losses Value :",a);//losses) Print("Loss Added, Profit:",profit);//profit); b++; if (profit > 0) Print("Wins Value :",b);//wins) Print("Win Added, Profit:",profit);//profit); losses++; if (a == 1) wins++; if (b == 1) Print("Number of trades :",returns);//returns) } else { PrintFormat("In total, in the history %d of deals, we couldn't select a deal"+ " with the index %d. Error %d",deals,deals-1,GetLastError()); }
Global variable will increment to 1 but the variable will not store incrementing to 2.
Is to possible to update a global variable from within the current function?
I've tried multiple variation what am I missing or is there a post, article anything that can lead me into the right direction?
My understanding at this point is that local variables will take preference
and always return 1 and reset to 0 everything the function is called
i would like to increment the global variable so that it displays 2
so that i can use that information in another function.
Global variable will increment to 1 but the variable will not store incrementing to 2.
The last code posted doesn't make sense, where are the "{ }" ?
What is the value of wins variable at the start of ScanClosedTrades() function ?
We don't know what you have in your history, so it's impossible to us to say how this code will be executed.
The last code posted doesn't make sense, where are the "{ }" ?
What is the value of wins variable at the start of ScanClosedTrades() function ?
We don't know what you have in your history, so it's impossible to us to say how this code will be executed.
I started reading lots of c++ tutorials in using the ++ arithmetic operation.
The function created was trying to manipulate the global int's Losses = 0 and Wins = 0 by incrementation.
Big No No. From the tutorials I read.
I created a class instead as recommended and all seem to be functioning as desired.
Here is the code and library. In case someone else needs help.
//--- Scan Closed Trades double ScanClosedTrades() { HistorySelect(0,TimeCurrent()); int a = 0; int b = 0; int c; int d; int deals = HistoryDealsTotal(); ulong ticket = HistoryDealGetTicket(deals-1); double profit = 0; if(ticket>0) { profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); if (profit < 0) { a++; { Print("Losses Value :",a);//losses) Print("Loss Added, Profit:",profit);//profit); } } else { b++; { Print("Wins Value :",b);//wins) Print("Win Added, Profit:",profit);//profit); } } if (a == 1) { Tally.AddLoss(); c = Tally.GetLoss(); Print("Current Loss Tally :",c);//Loss Tally) } if (b == 1) { Tally.AddWin(); d = Tally.GetWin(); Print("Current Win Tally :",d);//Win Tally) } } else { PrintFormat("In total, in the history %d of deals, we couldn't select a deal"+ " with the index %d. Error %d",deals,ticket,GetLastError()); } return(profit); }
What a great learning experience.
Thank you again angevoyageur adding the braces was needed you are 100 percent correct.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Tracking wins, and losses
After every order only one is shown.
2014.05.31 04:41:49 Core 1 2014.05.28 00:00:00 Wins Value :1.0
2014.05.31 04:41:50 Core 1 2014.05.29 00:00:00 Wins Value :1.0
The new value should be 2.