In the strategy tester the alerts are printed in the journal, so you will need to check there.
The checks that you are doing should only be executed when a new bar opens or you will get alerts every tick.
static datetime barTime=0; datetime thisBarTime=Time[0]; if(barTime!=thisBarTime) { barTime=thisBarTime; //Code to be executed only once when a new bar opens }
Please don't start a new topic concerning the same code.
I will copy your other post below and delete your new topic.
I note that you have completely ignored my advice and still calculating every tick!
Except for the stochastic which for some reason you are calculating globalscope instead of in OnTick().
First off, I want to point out that I'm new to coding with very limited formal training (udemy only). I wrote what I believe is a straightforward code but I'm not getting the results I expected. I wrote an EA to locate shooting stars/hammers based on some simple criteria like if the top wick is 3 x the size of the body and the bottom wick is less than 1/5 of the top wick than it's a shooting star. It's just a guideline for now. I can tweak the proportions later. I set the EA to draw a vertical line before this candle wherever it's identified. It seemed to do that much ok. Then I added a stochastic value and told the EA to only say that it's a shooting star when stochastic is over 80 and only say that it's a hammer when stochastic is below 20 but for whatever reason these instructions seem to be completely ignored. I don't understand what I'm doing wrong. I would really appreciate your help. Thanks in advance!
#property strict #include <CustomFunctions01.mqh> #property show_inputs // Adding all the global variables: //----------------------------------------------- // Parts of the candle double topWick; double body; double bottomWick; double stochValue = iStochastic(_Symbol,_Period,14,3,3,MODE_SMA,0,MODE_SIGNAL,1); // Is there a pattern bool bIsShootingStar = FALSE; bool bIsHammer = FALSE; // Inputs input double tailSize = 3; //multiples of body, refers to the long wick on the pattern input double wickSize = 0.2; //multiples of tail, refers to the short wick on the pattern input double stochUpperLevel = 80; //Stochastic Upper Level input double stochLowerLevel = 20; //Stochastic Lower Level int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { // Is the candle bullish or not? if(Open[1]<=Close[1]) { topWick = High[1]-Close[1]; body = Close[1]-Open[1]; bottomWick = Open[1]-Low[1]; } else { topWick = High[1]-Open[1]; body = Open[1]-Close[1]; bottomWick = Close[1]-Low[1]; } // Is it a shooting star? if (topWick >= body * tailSize && bottomWick <= topWick * wickSize && stochValue >= stochUpperLevel) { ObjectCreate(NULL,TimeCurrent(),OBJ_VLINE,0,Time[2],0); Alert("Shooting Star Found"); bIsShootingStar = TRUE; } // Is it a hammer? if (bottomWick >= body * tailSize && topWick <= topWick * wickSize && stochValue <= stochLowerLevel) { ObjectCreate(NULL,TimeCurrent(),OBJ_VLINE,0,Time[2],0); Alert("Hammer Found"); bIsHammer = TRUE; } }
Please don't start a new topic concerning the same code.
I will copy your other post below and delete your new topic.
I note that you have completely ignored my advice and still calculating every tick!
Except for the stochastic which for some reason you are calculating globalscope instead of in OnTick().
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm new to programming. MQL4 is my first coding language (and only for that matter). I'm trying to write a basic code that sends an alert when either a shooting star or a hammer is formed. I have two questions after putting this through the strategy tester on MT4. First, no alerts have been sent to I just want to make sure, alerts still get sent on the strategy tester, right? Assuming they do then something must just be missing from my code. The second question is, once is able to send the alert, is it going to send the alert on every single tick over and over? Is there something I'm supposed to write in there to make sure it only sends the alert once?
Anyways, here's my code. Thank you in advance. The code is simply meant to send an alert when the long wick is three times the length of the body or more and the short wick is 1/5 the length of the long wick or less. It's also worth noting, I've only written scripts before, so I'm not even sure I'm writing this correctly for an EA. Your help is greatly appreciated!