Metatrader 4 Expert advisor with custom indicator problem
Metatrader 4 Expert advisor with custom indicator problem
Loading saved threads...
Josip Marić · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Josip Marić
Original post: https://stackoverflow.com/questions/66250017
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
So it basically has 3 lines, and i want for long trades that closed bar price has crossed middle line up, but not upper line. i Cannot get it work in my if statement.
At the moment i do get middle line cross up, but it also shows buy signal if candle crosses upper line which is not good. Please help...
my EA code:
// the input variables of the EA
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
input int AMAPeriod = 10;
input ENUM_APPLIED_PRICE AMAPrice = PRICE_CLOSE;
input int Nfast = 2;
input int Nslow = 30;
input double GCoeff = 2;
input int PriceFilter = 5;
input maTypes PriceFilterMode = ma_smoo;
input bool Interpolate = true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double band_middle = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,0 );
double band_1 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode,Interpolate, 1,0 );
double band_2 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode,Interpolate, 2,0 );
double band_3 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 3,0 );
double band_up = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,0 );
double band_down = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 5,0 );
//strategy
double band_middle_curr = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,0 );
double band_middle_prev = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,1 );
double band_up_prev = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,1 );
double band_up_curr = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,0 );
Comment(band_up_prev);
if(Close[0] > band_middle_curr && Close[0] < band_up_curr)
{
Print("open a buy order");
}
}
//+------------------------------------------------------------------+
Quote
Report
Beertje · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Beertje
Original post: https://stackoverflow.com/a/69486083
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Use Close[1]. Close[0] is the current bar which is not finished yet.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Beertje Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/69486083 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Use Close[1]. Close[0] is the current bar which is not finished yet.
Checking account access…