Как кодировать? - страница 325

 

Код

cja:
Привет mladen,

Есть время взглянуть на это?

Дружеские пожелания CJA

Привет, Младен,

Хочу сообщить вам, что я получил решение по моему запросу о трейлинг-коде, так что вы можете исключить его из своего списка.

С уважением, CJA

 

Рад, что вы решили эту проблему.

Счастливого дальнейшего кодирования и торговли

cja:
Привет, Младен,

Небольшое замечание, чтобы сообщить вам, что я получил решение моей просьбы о трейлинг-коде, так что вы можете исключить это из своего списка дел.

С уважением, CJA
 

Привет,

Мне нужно проверить, был ли последний закрытый ордер моего советника в прибыли или убытке.

Я думал проверить два последних закрытых ордера советника с прибылью и просуммировать их.

Проблема в том, что у меня несколько советников на одном счете, поэтому необходимо проверить исторический ордер с определенным MagicNumber. Я пробую в нескольких режимах, но безуспешно.

Можете ли вы мне помочь?

Спасибо

 

dasio

Эта функция возвращает прибыль по последним закрытым ордерам (как видите, вы можете указать магическое число в качестве параметра, так что это решает вашу проблему с несколькими экземплярами):

double lastOrderProfit(int magicNumber=0)

{

datetime lastTime = 0;

double lastProfit = 0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderCloseTime() <= lastTime) continue;

lastTime = OrderCloseTime();

lastProfit = OrderProfit()+OrderSwap()+OrderCommission();

}

return(lastProfit);

}

Вам нужно только проверить, была ли прибыль от функции положительной или отрицательной.

dasio:
Здравствуйте,

Мне нужно проверить, был ли последний закрытый ордер моего ea в прибыли или убытке.

Я думал проверить два последних закрытых ордера советника с прибылью и просуммировать их.

Проблема в том, что у меня несколько советников на одном счете, поэтому необходимо проверить исторический ордер с определенным MagicNumber. Я пробую в нескольких режимах, но безуспешно.

Можете ли вы мне помочь?

Спасибо.
 
mladen:
dasio

Эта функция возвращает прибыль последнего закрытого ордера (как вы видите, вы можете указать магическое число в качестве параметра, так что это решает вашу проблему с несколькими экземплярами):

double lastOrderProfit(int magicNumber=0)

{

datetime lastTime = 0;

double lastProfit = 0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderCloseTime() <= lastTime) continue;

lastTime = OrderCloseTime();

lastProfit = OrderProfit()+OrderSwap()+OrderCommission();

}

return(lastProfit);

}
Вам нужно только проверить, был ли возврат от функции положительным или отрицательным.

То есть мне нужно только вызвать функцию с моим magicnumber и она выведет мне прибыль последнего закрытого ордера моей ea, верно?

 

Да, все правильно.

dasio:
То есть мне нужно только вызвать функцию с моим magicnumber и она выведет мне прибыль последнего закрытого ордера моей ea, верно?
 
mladen:
Да, это правильно

Спасибо.

Но если я запускаю ea и в истории нет ордера, как я могу вызвать функцию, только если ea закроет позицию?

 

Тогда сначала используйте эту функцию:

int closedSoFarForMagic(int magicNumber=0)

{

int closedSoFar=0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;

if (magicNumber!=0)

if (OrderMagicNumber() != magicNumber) continue;

if (OrderSymbol() != Symbol()) continue;

closedSoFar++;

}

return(closedSoFar);

}

Если closedSoFarForMagic() > 0, то вы знаете, что в истории уже есть закрытые ордера для определенного магического числа, и тогда вы можете проверить прибыль последнего ордера.

dasio:
Спасибо. Но если я запускаю ea и в истории нет ордеров, как я могу вызвать функцию, только если ea закроет позицию?
 

индикатор пересечения vma

Здравствуйте, я пытаюсь сделать индикатор, который показывает стрелки при пересечении двух vma. Я начинающий mql и мой индикатор явно не работает, я застрял. Кто-нибудь может мне помочь?

Оригинальный индикатор - MA - fantail vma 3

#property copyright "Copyright © 2007, Forex-TSD.com "

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

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Black

#property indicator_width1 2

//#property indicator_color2 Red

//#property indicator_width2 2

//---- input parameters

//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.

extern int ADX_Length=2;

extern double Weighting=2.0;

extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.

extern int MA_Mode=1;

//---- buffers

double MA[];

double VMA[];

double VarMA[];

double ADX[];

double ADXR[];

double sPDI[];

double sMDI[];

double STR[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,MA);

SetIndexBuffer(1,VMA);

// SetIndexStyle(2,DRAW_LINE);

SetIndexBuffer(2,VarMA);

SetIndexBuffer(3,ADX);

SetIndexBuffer(4,ADXR);

SetIndexBuffer(5,sPDI);

SetIndexBuffer(6,sMDI);

SetIndexBuffer(7,STR);

//---- name for DataWindow and indicator subwindow label

string short_name="MA - Fantail vma 3";

IndicatorShortName(short_name);

SetIndexLabel(0,"MA - Fantail vma 3");

//----

SetIndexDrawBegin(0,2*MA_Length+40);

// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.

//---- Safety limits for user settings

if (ADX_Length<2)ADX_Length=2;

if (ADX_Length>8)ADX_Length=8;

if (Weighting<1)Weighting=1;

if (Weighting>8)Weighting=8;

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit, i, j, counted_bars=IndicatorCounted();

//----

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

if ( counted_bars ==0 ) limit=Bars-1;

if ( counted_bars < 1 )

for(i=1;i<2*(MA_Length+ADX_Length+10);i++)

{

VMA=Close;

VarMA=Close;

MA=Close;

STR = High-Low;

sPDI = 0;

sMDI = 0;

ADX=0;

ADXR=0;

}

if(counted_bars>0) limit=Bars-counted_bars;

limit--;

for(i=limit; i>=0; i--)

{

double Hi = High;

double Hi1 = High;

double Lo = Low;

double Lo1 = Low;

double Close1= Close;

double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));

double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));

if (Bulls > Bears) Bears = 0;

else

if (Bulls < Bears) Bulls = 0;

else

if (Bulls == Bears) {Bulls = 0;Bears = 0;}

sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting

sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting

double TR = MathMax(Hi-Lo,Hi-Close1);

STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting

if(STR>0 )

{

double PDI = sPDI/STR;

double MDI = sMDI/STR;

}

if((PDI + MDI) > 0)

double DX = MathAbs(PDI - MDI)/(PDI + MDI);

else DX = 0;

ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting

double vADX = ADX;

double ADXmin = 1000000;

for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);

double ADXmax = -1;

for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);

double Diff = ADXmax - ADXmin;

if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;

VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.

}

for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);

//----

return(0);

}

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

[/PHP]

and this is mine

[PHP]

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

//| VMA cross arrows.mq4 |

//| thefxpros@katamail.com |

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

#property copyright "thefxpros"

#property link "thefxpros@katamail.com"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 C'255,198,198'

#property indicator_color2 C'198,255,198'

#property indicator_color3 Crimson

#property indicator_color4 DarkGreen

#property indicator_width1 3

#property indicator_width2 3

#property indicator_width3 2

#property indicator_width4 2

//--------------------------------------------------------

extern int VMA1_ADXLenght = 2;

extern double VMA1_Weighting = 2.0;

extern int VMA1_Length = 1;

extern int VMA1_Mode = 1;

extern int VMA2_ADXLenght = 2;

extern double VMA2_Weighting = 3.0;

extern int VMA2_Length = 3;

extern int VMA2_Mode = 2;

//--------------------------------------------------------

double buffer1[];

double buffer2[];

double buffer3[];

double buffer4[];

//--------------------------------------------------------

int init()

{

SetIndexStyle (0,DRAW_HISTOGRAM);

SetIndexStyle (1,DRAW_HISTOGRAM);

SetIndexBuffer (0,buffer3);

SetIndexBuffer (1,buffer4);

SetIndexBuffer (2,buffer1);

SetIndexBuffer (3,buffer2);

return(0);

}

int deinit()

{

return(0);

}

//--------------------------------------------------------

int start()

{

int counted_bars=IndicatorCounted();

int limit,i;

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//--------------------------------------------------------

for(i=limit; i>=0; i--)

{

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);

buffer3 = buffer1;

buffer4 = buffer2;

}

return(0);

}

 

thefxpros,

Сначала проверьте название индикатора:

"MA - fatailvma 3".

Там должно быть "fantail".

Кроме того, в вызове индикатора iCustom() не хватает номера буфера. Я просто предполагаю, что это то, чего вы пытались достичь.

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode,0, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode,1, i);[/PHP]

thefxpros:
Hi, i'm trying to make an indicator that shows arrows when two vma crosses. I'm a mql beginner and my indicator obviously does not work, I'm stuck. Somebody can help me?

The original indicator is MA - fantail vma 3

#property copyright "Copyright © 2007, Forex-TSD.com "

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

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Black

#property indicator_width1 2

//#property indicator_color2 Red

//#property indicator_width2 2

//---- input parameters

//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.

extern int ADX_Length=2;

extern double Weighting=2.0;

extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.

extern int MA_Mode=1;

//---- buffers

double MA[];

double VMA[];

double VarMA[];

double ADX[];

double ADXR[];

double sPDI[];

double sMDI[];

double STR[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

IndicatorBuffers(8);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,MA);

SetIndexBuffer(1,VMA);

// SetIndexStyle(2,DRAW_LINE);

SetIndexBuffer(2,VarMA);

SetIndexBuffer(3,ADX);

SetIndexBuffer(4,ADXR);

SetIndexBuffer(5,sPDI);

SetIndexBuffer(6,sMDI);

SetIndexBuffer(7,STR);

//---- name for DataWindow and indicator subwindow label

string short_name="MA - Fantail vma 3";

IndicatorShortName(short_name);

SetIndexLabel(0,"MA - Fantail vma 3");

//----

SetIndexDrawBegin(0,2*MA_Length+40);

// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.

//---- Safety limits for user settings

if (ADX_Length<2)ADX_Length=2;

if (ADX_Length>8)ADX_Length=8;

if (Weighting<1)Weighting=1;

if (Weighting>8)Weighting=8;

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit, i, j, counted_bars=IndicatorCounted();

//----

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

if ( counted_bars ==0 ) limit=Bars-1;

if ( counted_bars < 1 )

for(i=1;i<2*(MA_Length+ADX_Length+10);i++)

{

VMA=Close;

VarMA=Close;

MA=Close;

STR = High-Low;

sPDI = 0;

sMDI = 0;

ADX=0;

ADXR=0;

}

if(counted_bars>0) limit=Bars-counted_bars;

limit--;

for(i=limit; i>=0; i--)

{

double Hi = High;

double Hi1 = High;

double Lo = Low;

double Lo1 = Low;

double Close1= Close;

double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));

double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));

if (Bulls > Bears) Bears = 0;

else

if (Bulls < Bears) Bulls = 0;

else

if (Bulls == Bears) {Bulls = 0;Bears = 0;}

sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting

sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting

double TR = MathMax(Hi-Lo,Hi-Close1);

STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting

if(STR>0 )

{

double PDI = sPDI/STR;

double MDI = sMDI/STR;

}

if((PDI + MDI) > 0)

double DX = MathAbs(PDI - MDI)/(PDI + MDI);

else DX = 0;

ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting

double vADX = ADX;

double ADXmin = 1000000;

for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);

double ADXmax = -1;

for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);

double Diff = ADXmax - ADXmin;

if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;

VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.

}

for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);

//----

return(0);

}

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

and this is mine

[PHP]

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

//| VMA cross arrows.mq4 |

//| thefxpros@katamail.com |

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

#property copyright "thefxpros"

#property link "thefxpros@katamail.com"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 C'255,198,198'

#property indicator_color2 C'198,255,198'

#property indicator_color3 Crimson

#property indicator_color4 DarkGreen

#property indicator_width1 3

#property indicator_width2 3

#property indicator_width3 2

#property indicator_width4 2

//--------------------------------------------------------

extern int VMA1_ADXLenght = 2;

extern double VMA1_Weighting = 2.0;

extern int VMA1_Length = 1;

extern int VMA1_Mode = 1;

extern int VMA2_ADXLenght = 2;

extern double VMA2_Weighting = 3.0;

extern int VMA2_Length = 3;

extern int VMA2_Mode = 2;

//--------------------------------------------------------

double buffer1[];

double buffer2[];

double buffer3[];

double buffer4[];

//--------------------------------------------------------

int init()

{

SetIndexStyle (0,DRAW_HISTOGRAM);

SetIndexStyle (1,DRAW_HISTOGRAM);

SetIndexBuffer (0,buffer3);

SetIndexBuffer (1,buffer4);

SetIndexBuffer (2,buffer1);

SetIndexBuffer (3,buffer2);

return(0);

}

int deinit()

{

return(0);

}

//--------------------------------------------------------

int start()

{

int counted_bars=IndicatorCounted();

int limit,i;

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//--------------------------------------------------------

for(i=limit; i>=0; i--)

{

buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);

buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);

buffer3 = buffer1;

buffer4 = buffer2;

}

return(0);

}

Причина обращения: