코딩 도움말..경보 대신 필터링할 지표를 얻으려면 어떻게 해야 합니까? - 페이지 3

 
elihayun:
가장 좋은 방법은 표시기를 사용하지 않는 것입니다. 가장 간단한 방법일 뿐입니다. 시작은 충분합니다.

U는 표시기에 대한 변경 사항을 보고 있습니다. 이것을 사용하려면 코드 내부에 올바른 이름을 쓰고 있는지 확인하십시오.

어떤 버퍼에 원하는 정보가 있는지 알고 있는 한 코드에 얼마나 많은 지표가 있는지는 중요하지 않습니다.

좋아, 그래서 당신은 simpest가 반드시 최선은 아니라고 말하고 있습니다 ... 더 나은 방법은 EA 내부에 표시기를 작성하는 것입니다 ... 그러나 교훈의 예를 따라 그렇게하는 것이 복사하기 위해 말한 유일한 부분입니다. EA는 반복 기능 부분이고 버퍼는 코드의 초기화 기능 부분에 있습니다...그래서 전체 표시기 코드를 EA에 복사해야 합니까? 가장 좋은 방법은 무엇입니까? ..EA의 표시기로? 보여주시겠습니까? 배우고 있는 것 같아요. 좋아요!

 
Aaragorn:
좋아, 그래서 당신은 simpest가 반드시 최선은 아니라고 말하고 있습니다 ... 더 나은 방법은 EA 내부에 표시기를 작성하는 것입니다 ... 그러나 교훈의 예를 따라 그렇게하는 것이 복사하기 위해 말한 유일한 부분입니다. EA는 반복 기능 부분이고 버퍼는 코드의 초기화 기능 부분에 있습니다...그래서 전체 표시기 코드를 EA에 복사해야 합니까? 가장 좋은 방법은 무엇입니까? ..EA의 표시기로? 보여주시겠습니까?

당연히 아니지. 논리 부분만. 실제로 나는 그것을하는 예가 있습니다 (나는 그것을 직접 작성하려고했지만 지금은 가격을 보는 새로운 방법을 연구하고 있으며 시간이 많이 걸립니다)

여기에서 받을 수 있습니다. (작동이 잘 안되고 수정하는 데 시간이 필요하지만 코드를 함께 결합하는 방법을 볼 수 있음)

이 EA에서는 동시에 가장자리에 도달하려는 TF를 설정하거나 하나의 TF만 사용할 수 있습니다.

파일:
ytt2_ea.mq4  6 kb
 
elihayun:
엄청난!!! 당신은 아이디어를 얻었다!!!!

그것은 완벽하게 작동합니다. 5M과 15M이 동시에 에지에 도달하는지 확인하려면 각 TF에서 값을 가져와 함께 테스트할 수 있습니다.

하지만 후자를 위해 남겨주세요....

좋은 선생님이 있어요.

이제 '그' 아이디어가 나에게 이 '최상의' 방법을 수행하고 EA 내부에 표시기를 작성하는 것에 대한 나머지 방법을 알려줍니다. EA에 복사된 버퍼를 가져오십시오. 삽입해야 하는 것 같은데요?

이 중 실제로 EA에서 복사해야 하는 양은 얼마입니까?

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

#property indicator_chart_window

#property indicator_buffers 5

#property indicator_color1 Red

#property indicator_color2 Black

#property indicator_color3 Blue

#property indicator_color4 Red

#property indicator_color5 Blue

double upper[], middle1[], middle2, lower[];

double Xup[], Xdown[];

extern int period = 34;

int init()

{

SetIndexStyle(0,DRAW_LINE,EMPTY,2);

SetIndexShift(0,0);

SetIndexDrawBegin(0,0);

SetIndexBuffer(0,upper);

SetIndexStyle(1,DRAW_LINE,EMPTY,2);

SetIndexShift(1,0);

SetIndexDrawBegin(1,0);

SetIndexBuffer(1,middle1);

SetIndexStyle(2,DRAW_LINE,EMPTY,2);

SetIndexShift(2,0);

SetIndexDrawBegin(2,0);

SetIndexBuffer(2,lower);

SetIndexStyle(3,DRAW_ARROW,EMPTY,2);

SetIndexArrow(3, 162);

SetIndexShift(3,0);

SetIndexDrawBegin(3,0);

SetIndexBuffer(3,Xdown);

SetIndexStyle(4,DRAW_ARROW,EMPTY,2);

SetIndexArrow(4, 162);

SetIndexShift(4,0);

SetIndexDrawBegin(4,0);

SetIndexBuffer(4,Xup);

//---- indicators

//----

return(0);

}

아마도 지금 보여주신 방식대로 하고 표시기를 호출해야 할 것입니다.... 더 간단합니다.

 
Aaragorn:
좋은 선생님이 있어요.

이제 '그' 아이디어가 나에게 이 '최상의' 방법을 수행하고 EA 내부에 표시기를 작성하는 것에 대한 나머지 방법을 알려줍니다. EA에 복사된 버퍼를 가져오십시오. 삽입해야 하는 것 같은데요?

이 중 실제로 EA에서 복사해야 하는 양은 얼마입니까?

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

.......

//---- indicators

//----

return(0);

}
아마도 지금 보여주신 방식대로 하고 표시기를 호출해야 할 것입니다.... 더 간단합니다.

없음. 이것은 논리가 아니라 표시기의 시각적 부분입니다.

 

내가 지금까지 한 모든 것을 보여주려면 두 개의 게시물이 필요합니다....사이트는 모든 것을 한 번에 수락하지 않습니다...정보로 당신에게 과부하를 주지 마십시오...나는 단지 보여주고 싶습니다 당신은 내가 지금까지 무엇을 했는지...

전반전...

//+------------------------------------------------------------------+

//| EMA_CROSS_2.mq4 |

//| Coders Guru |

//| https://www.forex-tsd.com |

//+------------------------------------------------------------------+

// ultima versiune cu micro lots! H1 si D1

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

//---- Trades limits

extern double

TakeProfit = 10,

TrailingStop = 20,

StopLoss = 20;

extern bool

UseStopLoss = false;

//---- EMAs paris

extern int

ShortEma = 1,

LongEma = 5;

//---- Crossing options

extern bool

immediate_trade = true, //Open trades immediately or wait for cross.

reversal = false, //Use the originally reversal crossing method or not

ConfirmedOnEntry = false;

//---- Money Management

extern double

Lots = 1,

HedgePercent = 1; // Used to calcualte the what percent of the lots the user wants to be

// used in the hedged position

extern bool

MM = true, //Use Money Management or not

AccountIsMicro = true; //Use Micro-Account or not

extern int

StartHour = 0, //Indicates when the user wants the EA to start trading

StopHour = 23; //Indicates when the user wants the EA to stop trading

extern int

Risk = 10; //10%

extern int

MAGICMA = 20060301;

extern bool

Show_Settings = true;

//---- Global varaibles

static int

TimeFrame = 0;

datetime

CheckValueTime;

//---- Trend bands

double upper[], middle1[], middle2, lower[];

double Xup[], Xdown[];

extern int period = 34;

//---- Filter Parameters

extern double longrange = 25;

extern double shortrange = 20;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

if(Show_Settings) Print_Details();

else Comment("");

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

TimeFrame=Period(); //Prevent counting the cross while the user changing the timeframe

return(0);

}

bool isNewSumbol(string current_symbol)

{

//loop through all the opened order and compare the symbols

int total = OrdersTotal();

for(int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

string selected_symbol = OrderSymbol();

if (current_symbol == selected_symbol)

return (False);

}

return (True);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(TimeFrame!=Period())

{

TimeFrame=Period();

return (0);

}

if(line1>line2)current_direction = 1; //up

if(line1<line2)current_direction = 2; //down

if(immediate_trade==false)

{

if(last_direction == 0) //first use

{

last_direction = current_direction;

return(0);

}

}

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0); //not changed

}

}

//--- Bassed on Alex idea! More ideas are coming

double LotSize()

{

double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / 100;

if(AccountIsMicro==false) //normal account

{

if (lotMM < 0.1) lotMM = Lots;

if ((lotMM > 0.5) && (lotMM < 1)) lotMM=0.5;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

else //micro account

{

if (lotMM < 0.01) lotMM = Lots;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

return (lotMM);

}

string BoolToStr ( bool value)

{

if(value) return ("True");

else return ("False");

}

void Print_Details()

{

string sComment = "";

string sp = "----------------------------------------\n";

string NL = "\n";

sComment = sp;

sComment = sComment + "TakeProfit=" + DoubleToStr(TakeProfit,0) + " | ";

sComment = sComment + "TrailingStop=" + DoubleToStr(TrailingStop,0) + " | ";

sComment = sComment + "StopLoss=" + DoubleToStr(StopLoss,0) + " | ";

sComment = sComment + "UseStopLoss=" + BoolToStr(UseStopLoss) + NL;

sComment = sComment + sp;

sComment = sComment + "immediate_trade=" + BoolToStr(immediate_trade) + " | ";

sComment = sComment + "reversal=" + BoolToStr(reversal) + NL;

sComment = sComment + sp;

sComment = sComment + "Lots=" + DoubleToStr(Lots,0) + " | ";

sComment = sComment + "MM=" + BoolToStr(MM) + " | ";

sComment = sComment + "Risk=" + DoubleToStr(Risk,0) + "%" + NL;

sComment = sComment + sp;

Comment(sComment);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

 

후반...

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start() {

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

double avg;

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

return(0);

}

//+------------------------------------------------------------------+

double findAvg(int period, int shift) {

double sum=0;

for (int x=shift;x<(shift+period);x++) {

sum += High[x]-Low[x];

}

sum = sum/period;

return (sum);

}

bool NewBar()

{

static datetime dt = 0;

if (dt != Time[0])

{

dt = Time[0];

return(true);

}

return(false);

//end of trend bands custom indicator

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

{

if(Hour() >= StartHour && Hour() <= StopHour){ //Nothing will happen unless the time is within the trading time

int cnt, ticket, total;

double SEma, LEma, SEmaLAST, LEmaLAST;

string comment = "";

if(reversal==true) comment = "EMA_CROSS_Counter-Trend";

if(reversal==false) comment = "EMA_CROSS_Trend-Following";

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<1)

{

Print("TakeProfit less than 1");

return(0); // check TakeProfit

}

static int isCrossed = 0;

if(ConfirmedOnEntry)

{

if(CheckValueTime==iTime(NULL,TimeFrame,0)) return(0); else CheckValueTime = iTime(NULL,TimeFrame,0);

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,1);

SEmaLAST = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);

LEmaLAST = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,2);

if(SEmaLASTLEma) isCrossed = 1;

if(SEmaLAST>LEmaLAST && SEma<LEma) isCrossed = 2;

}

else

{

SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);

LEma = iMA(NULL,0,LongEma ,0,MODE_EMA,PRICE_CLOSE,0);

isCrossed = Crossed (LEma,SEma);

}

if(reversal==false)

{

if(isCrossed==1) isCrossed = 2;

else if(isCrossed==2) isCrossed = 1;

}

if(MM==true) Lots = LotSize(); //Adjust the lot size

total = OrdersTotal();

// TRAILING STOP

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

// ENTRY

if(total < 2 || isNewSumbol(Symbol())) //I have modified the if condition too: it was total<1 (orBanAway aka cucurucu)

{

double HedgeLots = (HedgePercent/100)*Lots; //calculates the Lots for the hedged position

if(isCrossed == 1 && Point < toplinevalue-longrange)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

//###################################################################### ends here

return(0);

}

if(isCrossed == 2)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

//###################################################################### ends here

return(0);

}

return(0);

}

return(0);

}

return(0);

}

}

//+------------------------------------------------------------------+

이제 내가 이 라인에 도달하면...

if(isCrossed == 1 && Point < toplinevalue-longrange)

이것은 현재 막대에 대한 표시기의 값을 입력하려는 곳입니다...

이미 EA 내부에 있는 현재 막대에 대해 위의 코드에서 정보를 호출하려면 어떻게 해야 합니까? 사실 icustom()으로 표시기를 호출하는 방법을 보여주기 전에 어제 이 작업을 많이 했습니다. 이미 한 모든 작업을 취소하기 전에 모든 작업을 취소하고 표시기를 호출하는 것보다 그대로 완료할 수 있는지 궁금합니다.

 

내가 말했듯이 U는 역사를 다룰 필요가 없습니다. 마지막 값을 얻기 위해 전체 버퍼를 채우고 있습니다.

for(int x=0; x<limit; x++) {

Xdown[x] = 0; Xup[x] = 0;

middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

upper[x] = middle2 + (3.5*avg);

lower[x] = middle2 - (3.5*avg);

if (MathAbs(upper[x] - High[x]) < 2*Point)

{

Xdown[x] = upper[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower[x] - Low[x]) < 2*Point)

{

Xup[x] = lower[x];

if (NewBar() && x == 0)

Alert(Symbol()," ",Period()," reach lower edge");

}

}

[/PHP]

Why not just calculate the last bar

[PHP]

int x = 0;

//Xdown[x] = 0; Xup[x] = 0;

//

// we are not using middle line

//middle1[x] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_TYPICAL, x);// drawn line

double middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

double upper = middle2 + (3.5*avg);

double lower = middle2 - (3.5*avg);

if (MathAbs(upper - High) < 2*Point)

{

// no need just alert (or open a trade)

//Xdown[x] = upper[x];

if (NewBar())

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower - Low) < 2*Point)

{

//Xup[x] = lower[x];

if (NewBar()) // I remove " && x == 0" because we know that x == 0

Alert(Symbol()," ",Period()," reach lower edge");

}

}

 
int x = 0;

double middle2= iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

avg = findAvg(period, x);

double upper = middle2 + (3.5*avg);

double lower = middle2 - (3.5*avg); [/php]

ok that makes sense, I don't need the whole array just the current bar, so this (above code) is all that is required to calculate the top and bottom lines that needs to be in the EA?

this part (code below) confused me. I don't get the logic of it..I know it's sending alerts when the line is crossed but that's not what I need to use this for. I don't understand how it works to make the Xdown = upper , nor do I understand the logic of upper - high <2*point . To me it is a mass of confusion.

all I need to do with the top and bottom lines is know where they are in the current bar so I can determine how close to allow the point to approach them before it disallows the trade? that is the logic I want to create with the right code. I don't need alerts. Also I have not been able to find 'newbar()' in the metaeditor dictionary and the search function in metaeditor isn't working for me it's not responsive.

[php] if (MathAbs(upper - High) < 2*Point)

{

// no need just alert (or open a trade)

//Xdown[x] = upper[x];

if (NewBar())

Alert(Symbol()," ",Period()," reach upper edge");

}

if (MathAbs(lower - Low) < 2*Point)

{

//Xup[x] = lower[x];

if (NewBar()) // I remove " && x == 0" because we know that x == 0

Alert(Symbol()," ",Period()," reach lower edge");

}

}

나는 MEdictionary를 보고 있었고 'bool IsTradeAllowed( )'가 너무 가깝다면 거래가 열리지 않도록 제한하는 데 사용할 수 있다는 것을 알았습니다.

 

상단 라인 이 가격에 가까운지 알고 싶은 경우 알아낼 수 있는 한 가지 방법은 둘 사이의 차이가 작은지(예: 2포인트)입니다.

나는 가격이 선 아래에 있든 선 위에 있든 상관하지 않습니다(좋은 생각은 아닙니다). 나를 위해 2 포인트 거리가 소요됩니다. 그래서 차이는

upper - High 는 diff를 제공하지만 포인트는 제공하지 않습니다(0.0004 또는 -0.0004와 같은 것). diff가 양수인지 확인하기 위해 절대(양수) 값을 반환하는 MathAbs finction을 사용하고 있습니다. 이제 2점 미만인지 확인해야 합니다. 예약어 Point 는 가격이 1핍으로 올라갈 때 값을 반환합니다. 짝마다 다릅니다.

모두 함께 넣어

if (MathAbs(upper - High) < 2*Point) 는 차이가 2핍보다 작고 우리에게 충분히 가까운 경우를 의미합니다.

실제로 High를 사용하는 것은 좋지 않습니다. High가 그 이상일 수도 있지만 현재 가격이 너무 멀기 때문입니다. High 대신 Ask 를 사용해야 합니다(표시기에서 Close[x] 를 사용해야 함).

가격이 선 위에 있는지 확인하기 위해 우리는 이것을 할 수 있습니다

if ((Ask > upper) && (Ask - upper < 2 * Point))

.....(alert or open a trade)

 

이것까지 끓였는데..기다려..

이것이 고점을 찾기 위해 3.5를 곱한 이 한 막대의 단순 이동 평균 을 사용하는 경우입니다. 어떻게 그 지점이 여기까지 올 수 있단 말인가? 라인 값이 신호를 보내기 위해 터치해야 하는 동일한 막대에서 계산되고 있지 않습니까? 바가 올라갈수록 엣지 라인도 올라가나요???

//----------channel filter

double middle2= iMA(NULL, 0, back, 0, MODE_SMA, PRICE_TYPICAL, 0);// only used to calculate outer bands

double avg;

avg = findAvg(back, x);

double upper = middle2 + (3.5*avg);

double lower = middle2 - (3.5*avg);