molanis.com/forum - Tools for MetaTrader : The place to ask about the best expert advisor builder, expert advisor downloads, and expert advisor programming http://www.molanis.com/forum/ |
|
Custom Indicator MA Cross, where is the Signal??? http://www.molanis.com/forum/viewtopic.php?f=2&t=341 |
Page 1 of 1 |
Author: | metapro [ Sun May 01, 2011 4:13 am ] |
Post subject: | Custom Indicator MA Cross, where is the Signal??? |
Hey, I have this custom indicator and would like to use it for long signal. My idea is to go long if indicator X's and this custom indicator send both long signals at the same time. It is important to mention that this custom indicator sometimes send signals shortly before or after indicator X send its long signal. Therefore, several shifts might be required. How do I implement this indicator in the strategy builder correctly? Code: #property indicator_chart_window
#property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Green //---- double CrossUp[]; double CrossDown[]; double prevtime; double Range, AvgRange; double fasterMAnow, fasterMAprevious, fasterMAafter; double mediumMAnow, mediumMAprevious, mediumMAafter; double slowerMAnow, slowerMAprevious, slowerMAafter; //---- extern int FasterMA = 5; extern int FasterShift = -5; extern int FasterMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int MediumMA = 20; extern int MediumShift = -5; extern int MediumMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int SlowerMA = 34; extern int SlowerShift = 0; extern int SlowerMode = 1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma extern int SoundAlert = 1; // 0 = disabled //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; //---- limit=Bars-counted_bars; //---- for(i = 0; i <= limit; i++) { counter=i; Range=0; AvgRange=0; for (counter=i ;counter<=i+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); } Range=AvgRange/10; //---- fasterMAnow = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+1); fasterMAprevious = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+2); fasterMAafter = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i-1); //---- mediumMAnow = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+1); mediumMAprevious = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+2); mediumMAafter = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i-1); //---- slowerMAnow = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+1); slowerMAprevious = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+2); slowerMAafter = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i-1); //---- if ((fasterMAnow > slowerMAnow && fasterMAprevious <= slowerMAprevious && fasterMAafter > slowerMAafter && mediumMAnow > slowerMAnow ) || (fasterMAnow > slowerMAnow && mediumMAnow > slowerMAnow && mediumMAprevious <= slowerMAprevious && mediumMAafter > slowerMAafter )) { CrossUp[i] = Low[i] - Range*0.5; } if ((fasterMAnow < slowerMAnow && fasterMAprevious >= slowerMAprevious && fasterMAafter < slowerMAafter && mediumMAnow < slowerMAnow ) || (fasterMAnow < slowerMAnow && mediumMAnow < slowerMAnow && mediumMAprevious >= slowerMAprevious && mediumMAafter < slowerMAafter )) { CrossDown[i] = High[i] + Range*0.5; } } if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; } if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]) && (SoundAlert != 0)) { prevtime = Time[0]; Alert(Symbol()," 3 MA Cross Up @ Hour ",Hour()," Minute ",Minute()); } if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]) && (SoundAlert != 0)) { prevtime = Time[0]; Alert(Symbol()," 3 MA Cross Down @ Hour ",Hour()," Minute ",Minute()); } //Comment(" CrossUp[0] ",CrossUp[0]," , CrossDown[0] ",CrossDown[0]," , prevtime ",prevtime); //Comment(""); return(0); } |
Author: | molanisfx [ Sun May 01, 2011 9:04 am ] |
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? |
Do this: Change the last indicator line to Comment(" CrossUp[0] ",CrossUp[0]," , CrossDown[0] ",CrossDown[0]," , prevtime ",prevtime); instead of //Comment(" CrossUp[0] ",CrossUp[0]," , CrossDown[0] ",CrossDown[0]," , prevtime ",prevtime); That way you will see the indicator's value (signals) in the screen. You will see that when there is no signal the indicator's value is 2147483647. (That's mt4 way of saying the value is empty or there is no value.) Thus your conditions need to take that into account: -There are 2 signals, buy and sell -When there are no signals present the indicator's value is a number : 2147483647 -For a buy (cross up) a condition would be like indicator mode 1 < 2147483647 (we always use <100000) AND indicator mode 1 > 0 This has been explained several times here viewtopic.php?f=3&t=162 |
Author: | metapro [ Sun May 01, 2011 5:47 pm ] | ||
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? | ||
Ok sounds good! But how do I apply it correctly if you have a look at my chart. The red arrows are the indicator you see above and the green arrows are another one. As you can see, usually they do not really appear coincidently. However, even when there is a long signal with these two arrows within a certain time-lag they work pretty well (only for long signals though). Now my question is: Would this be realizable? Thanks P EDIT: I forgot to attach the charts!
|
Author: | molanisfx [ Mon May 02, 2011 9:16 am ] |
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? |
So you want to use 2 different indicators that give signals at a different time, sometimes with a lag, sometimes at the same time. Putting the strategy in words would be like, if x indicator has a signal, check y indicator. The problem here is defining when to check y indicator. Current / previous bar? Three bars? The easiest way would be to transform y indicator to give continue signals. Unfortunately some coding is required. |
Author: | metapro [ Thu May 05, 2011 10:30 am ] | ||
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? | ||
I just made my own indicator with the Indicator Builder. I attached the Indicator. In my EA I'd like to include it like buy if(ICustom>0). I used Mode 2 (since I'd like to use the second signal) and shift 0. However, no long or short trade was triggered in my backtesting.
|
Author: | molanisfx [ Thu May 05, 2011 3:32 pm ] |
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? |
Please post the strategy file .mol file and a description of the ea logic (when to buy / sell) |
Author: | metapro [ Thu May 05, 2011 3:40 pm ] | ||
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? | ||
long if change from - to + and vice versa for short. Obviously the indicator itself won't be profitable but at least it should send out orders.
|
Author: | molanisfx [ Fri May 06, 2011 1:02 pm ] |
Post subject: | Re: Custom Indicator MA Cross, where is the Signal??? |
Next time, if you change topics, please start a new thread When you generate the indicator it shows you the signal. It should show this: //***Read this first: Integration with Molanis Strategy Builder*** /*To integrate this indicator with Molanis Strategy Builder use the following modes: Mode 0 = (iRSI(NULL,0,9,PRICE_WEIGHTED,i)-iRSI(NULL,0,9,PRICE_WEIGHTED,i+3)); This means that to get that signal you need to use Mode 0 within the strategy builder. Please read our examples to understand the difference between using conditions like rsi>0 and a cross rsi. http://www.molanis.com/products/molanis ... rs-for-mt4 |
Page 1 of 1 | All times are UTC - 5 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |