Need a little coding help

User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need a little coding help

Post by LittleCaro »

Hello,

I'm in the making of an ea with the incredible steve's shell.

It is based on a step ma, and what i want is when the step ma changes color, we send a trend, we take our profit and we wait another change color to send the trade.

Here is how i include it in the shell :

Code: Select all

double clnow = iCustom(_Symbol,BuzzerTimeFrame,"Buzzer",Price,Length,AlertON,EmailON,3,clbar);
double clpre = iCustom(_Symbol,BuzzerTimeFrame,"Buzzer",Price,Length,AlertON,EmailON,3,clbar+1);
And the triger conditions :

Code: Select all

if (clnow>clpre) SendLong = true;
if (clnow<clpre) SendShort = true;
BUT i have a problem, after the TP is hit, the ea keeps opening trades in the same direction, where he should wait a change color to send trades.

What i want is only 1 trade per color.

I spend a lot of time on this, and i ask here if coders have an idea to stop the ea sending orders ?

Thanks !
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Need a little coding help

Post by SteveHopwood »

LittleCaro » Thu Nov 26, 2015 9:58 am wrote:
This should do the trick

Code: Select all

if (clnow>clpre && OpenTrades == 0) SendLong = true;
if (clnow<clpre && OpenTrades == 0) SendShort = true;
:xm:
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.
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need a little coding help

Post by LittleCaro »

Thanks for the help Steve, but it's not working.

What i need is stop send trades after the close of the trade.

The step ma changes color ------> it opens a trade ----> the trade close by hiting take profit ----> the expert stops sending trades.

And we repeat the cycle : step ma changes color ----> it opens a trade ------ >
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Need a little coding help

Post by SteveHopwood »

LittleCaro » Thu Nov 26, 2015 10:43 am wrote:Thanks for the help Steve, but it's not working.

What i need is stop send trades after the close of the trade.

The step ma changes color ------> it opens a trade ----> the trade close by hiting take profit ----> the expert stops sending trades.

And we repeat the cycle : step ma changes color ----> it opens a trade ------ >
Mql4 is the easiest and most basic language to code because it only needs to perform a limited number of functions. Mostly we have problems working out what to code - just as here.

Here, you need code that cycles back through the candles to detect the most recent colour change, and stored the candle shift in a variable. Your code will look something like this:

Code: Select all

//Declare these somewhere in your general declarations section - General inputs perhaps.
int            LatestColourChangeShift=0;
bool           ThisSessionAlreadyTraded=false;

//Then call this function from wherever you think appropriate = ReadIndicatorValues() seems the
//best place.
void HaveWeTradedThisColourChange()
{

   //Find the most recent colour change
   for (int cc = 1; cc < iBarShift(Symbol(), TradingTimeFrame); cc++)
   {
      //Insert code to call the GetTheCrapCustomAbortion function that reads the step ma,
      //and detect the most recent colour change. When this is detected:
      LatestColourChangeShift = cc;
      Alert(LatestColourChangeShift);//As a check. Delete as soon as you are certain this works
      break;
   }//for (int cc = 1; cc < iBarShift(Symbol(), TradingTimeFrame); cc++)
   
   //We have the candle shift of the most recent colour change, so examine closed trades
   //in the History to see if we have a post-shift trade closure.
   ThisSessionAlreadyTraded = false;
   if (OrdersHistoryTotal() == 0)
      return;
   
   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      
      //Delete whichever of the following snippets you do not need.
      if (OrderOpenTime() >= iTime(Symbol(), TradingTimeFrame, 0) )
      {
         ThisSessionAlreadyTraded = true;
         return;
      }//if (OrderOpenTime() >= iTime(Symbol(), TradingTimeFrame, 0) )
      
      if (OrderCloseTime() >= iTime(Symbol(), TradingTimeFrame, 0) )
      {
         ThisSessionAlreadyTraded = true;
         return;
      }//if (OrderCloseTime() >= iTime(Symbol(), TradingTimeFrame, 0) )
      

   }//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
      
   
}//void HaveWeTradedThisColourChange()

//Then add this line to bool IsTradingAllowed()
if (ThisSessionAlreadyTraded)
   return(false);
I have not compiled this or tested it, so any minor bloops will cause the compiler to whinge.

Great to see you getting to grips with this stuff. You will not regret doing so in the long term, however demented you may be driven when devising the algorithm.

:xm:
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.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Need a little coding help

Post by SteveHopwood »

I meant to click 'Quote' on your post, but instead clicked 'Edit', so the post contents have disappeared.

Do me a favour, please: repost your function here and send me the crap custom abortion in a pm so I can see on my chart what you are looking at.

:xm:
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.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Need a little coding help

Post by SteveHopwood »

I just had a bath and thought about all this.

Send me both your EA as coded so far so I can copy the inputs, and the CCA. I will show you the steps I take when doing battle with these thingies as series of tutorials here, so others can benefit should they wish to.

:xm:
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.
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need a little coding help

Post by LittleCaro »

Ok Steve, i repost here the first part of the tutorial, and on the next post i will upload te indicator the ea and template.

So, i don't understand how to integrate the color change of stepma, i try this :

Code: Select all

void HaveWeTradedThisColourChange()
{
 
   //Find the most recent colour change
   for (int cc = 1; cc < iBarShift(Symbol(), TradingTimeFrame,cc); cc++)
   {
      //Insert code to call the GetTheCrapCustomAbortion function that reads the step ma,
      //and detect the most recent colour change. When this is detected:
   
double clrch = iCustom (_Symbol,StepMaTimeframe,"StepMA new 1.05",Sensitivity,StepSize,Shift,Prices,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotification,0,clbar);
double clrch1  = iCustom (_Symbol,StepMaTimeframe,"StepMA new 1.05",Sensitivity,StepSize,Shift,Prices,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotification,0,clbar+1);
    
      if (clrch > clrch1) LatestColourChangeShift;
      if (clrch < clrch1) LatestColourChangeShift;
      
      
      LatestColourChangeShift = cc;
      Alert(LatestColourChangeShift);//As a check. Delete as soon as you are certain this works
      break;
   }//for (int cc = 1; cc < iBarShift(Symbol(), TradingTimeFrame); cc++)
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need a little coding help

Post by LittleCaro »

Here i post the expert and indicator and template for euro in 15 minutes.

You will see in the expert i make a lot of good shit, i tried to check the history to search if previous trade was long or short, so it'll filter all the trades, but with no result.

I modified also the take profit, because if expert detects a loss, the TP must be higher.


What we want to achieve in this thread, is to simply get only 1 trade per colour change once the TP is hit.

Thanks Steve this will be really cool to learn something new.
You do not have the required permissions to view the files attached to this post.
AnotherBrian

Need a little coding help

Post by AnotherBrian »

SteveHopwood » Fri Nov 27, 2015 5:52 am wrote:I just had a bath and thought about all this.

Send me both your EA as coded so far so I can copy the inputs, and the CCA. I will show you the steps I take when doing battle with these thingies as series of tutorials here, so others can benefit should they wish to.

:xm:
Great idea Steve, examples will help newbies to get started, and that helps all of us.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Need a little coding help

Post by SteveHopwood »

AnotherBrian » Fri Nov 27, 2015 2:40 pm wrote:
Great idea Steve, examples will help newbies to get started, and that helps all of us.
I worked on this today. Tomorrow I will start to describe the process I go through when faced by a Crap Custom Abortion that someone is daft enough to want me to turn into an EA.

This process includes learning how to drag useful information from uncooperative CCA's. The one that Little Caro posted here is a long, long way from being the worst I have ever encountered, but even so can be confusing unless you have spent nearly 10 years battling with the bloody thingies and understand the tricks that the dafter of the CCA coders have up their sleeves.

:xm:
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.
Post Reply

Return to “Coders Hangout”