not sure if this post is in correct place, but here goes...
I am a beginner-coder, and have come to a block wall; i am unable to find solution mentioned in any of my coding material!
I have condition, if cross-under (number of open trades), but i want to add "&& if most recent trade closed was at a loss"; then open trade. What do i add after && ??
Appreciate your answer or even advise where to go find the answer myself, THANKS.
coding help; if closed trade was at loss...
-
revotrader
- Posts: 7
- Joined: Wed Feb 03, 2016 12:27 pm
- Location: GYMPIE, QLD, AUSTRALIA
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
coding help; if closed trade was at loss...
Without knowing anything more about your requirements, you can do something like this:revotrader » Sun Feb 21, 2016 10:52 am wrote:not sure if this post is in correct place, but here goes...
I am a beginner-coder, and have come to a block wall; i am unable to find solution mentioned in any of my coding material!
I have condition, if cross-under (number of open trades), but i want to add "&& if most recent trade closed was at a loss"; then open trade. What do i add after && ??
Appreciate your answer or even advise where to go find the answer myself, THANKS.
Code: Select all
double profit = 0.0;
if ( OrderSelect( OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY ) ) {
profit = OrderProfit() + OrderSwap() + OrderCommission();
}
if ( /* cross-under */ && ( profit < 0.0 ) ) {
// Open trades ...
}
Hope this helps.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
coding help; if closed trade was at loss...
Code: Select all
double profit = 0;
//Loop backwards through the history tab to find the first trade owned by the EA
for (int cc = 0; cc <= OrdersHistoryTotal(); cc++)
{
//Does the EA 'own' this trade
if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
if (OrderSymbol() != Symbol() ) continue;
if (OrderMagicNumber() != MagicNumber) continue;
//We have got this far, so we have found a trade owned by the ea.
profit = OrderSwap() + OrderProfit() + OrderCommission();
//Was it a loser?
if (profit < 0)
if (cross under requirement is met)
{
do stuff to send the trade
}//if (cross under requirement is met)
//EITHER
//Nothing else to do, so exit the function
return;
//OR
//Nothing else to do, so exit the loop
break;
}//for (int cc = 0; cc <= tot -1; cc++)
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
revotrader
- Posts: 7
- Joined: Wed Feb 03, 2016 12:27 pm
- Location: GYMPIE, QLD, AUSTRALIA
coding help; if closed trade was at loss...
wow! amazing, fast responses, thanks. pre-lim testing shows change in p/l, so my added code appears to have made a change, now to test it if it works in real time pa! woohoo!
Thanks again.
Thanks again.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
coding help; if closed trade was at loss...
Up an' at 'em, Tiger.revotrader » Sun Feb 21, 2016 11:24 pm wrote:wow! amazing, fast responses, thanks. pre-lim testing shows change in p/l, so my added code appears to have made a change, now to test it if it works in real time pa! woohoo!
Thanks again.
I was once where you are now. Keep at it. You will not be sorry in the long term. Short term: misery and pain. Hey ho.
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
revotrader
- Posts: 7
- Joined: Wed Feb 03, 2016 12:27 pm
- Location: GYMPIE, QLD, AUSTRALIA
coding help; if closed trade was at loss...
after testing, my code was major fail. I have attached my code.
Please add code "if trade closed at loss" to each of the crossunder conditions to open trades.
Please add code "if trade closed at loss" to each of the crossunder conditions to open trades.
You do not have the required permissions to view the files attached to this post.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
coding help; if closed trade was at loss...
Give anybody here one single reason for adding the code you require. What do they have to gain? You come across as a wet wimp who does not deserve help.
You are perfectly entitled to ask for help - indeed there are many and varied people at shf only too willing to offer such help. They are prepared to help; they are not prepared to write your code for you free of charge. To ask them to do so is insulting.
I made my offering here on the assumption that you were genuinely trying to help yourself. Clearly I was wrong.
Stop being wet an pathetic and do some work for yourself.
Reason I am so unsympathetic? Working stuff out for myself is what I did. For hours and hours, over days and days, and weeks and weeks and months and months. For years.
Yes, I did ask for help. People were only too happy to give it because they had watched me work stuff out form myself for hours and hours..................................
Grow up. This thread is locked.
You are perfectly entitled to ask for help - indeed there are many and varied people at shf only too willing to offer such help. They are prepared to help; they are not prepared to write your code for you free of charge. To ask them to do so is insulting.
I made my offering here on the assumption that you were genuinely trying to help yourself. Clearly I was wrong.
Stop being wet an pathetic and do some work for yourself.
Reason I am so unsympathetic? Working stuff out for myself is what I did. For hours and hours, over days and days, and weeks and weeks and months and months. For years.
Yes, I did ask for help. People were only too happy to give it because they had watched me work stuff out form myself for hours and hours..................................
Grow up. This thread is locked.
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.