Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Atr stoploss (http://www.expert-advisor.com/forum/showthread.php?t=6899)

Manoo 27.01.21 14:22

Atr stoploss
 
Hallo an alle,

ich brauchte etwas Hilfe mit einer Art Indicator fuer meine Ordermodify fuer den SL.
Es soll eine Art Supertrend indicator werden der die ATR multiplieziert... habe es auch in die richtung versucht:

double ATR = iATR (_Symbol,0,30,1);
double atrMultiple = 3;

double STRSL = (ATR * atrMultiple / Point);

hat nicht wirklich geplappt... vielleicht kann jemand Helfen :)

Indikator-Trading 28.01.21 13:35

SL für eine Buy-Order:
SL = Bid + ATR*atrMultiple;

SL für eine Sell-Order:
SL = Ask + ATR*atrMultiple;

Das hat alles natürlich nichts mit dem Verlauf von dem Supertrend zutun, würde aber dem Werteverlauf vom ATR folgen.

Manoo 28.01.21 17:11

das funktioniert auch auf dem SL der Supertrend ist komplizierter zu gestalten.
Da muss man noch den Mittelwert der Perioden dazurechnen...
das weiss ich auch das Problem ist einfach, wie er in der Ordermodify immer den Wert neu berechnet und den Sl nachzieht?

Manoo 28.01.21 17:13

In die richtung habe ich es versucht....



for (int b= OrdersTotal()-1;b>=0;b--){

if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if (OrderSymbol()==Symbol()){
ticket = 1;}
if (OrderType()==OP_BUY){
if (OrderStopLoss() < STRSL)
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),STRSL,O rderTakeProfit(),0,CLR_NONE);
return;
}else if (OrderType()==OP_SELL){
if (OrderStopLoss() > STRSL)
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),STRSL,O rderTakeProfit(),0,CLR_NONE);
return;
}
}

Indikator-Trading 28.01.21 20:26

Das hat halt auch nichts mit dem supertrend zutun. Du musst dir doch einfach nur den Code vom supertrend anschauen ö, verstehen und umsetzen. Alternativ den direkten Wert vom Supertrend oder einem anderen, ähnlichen Indikator direkt nutzen ohne das selbst noch in den EA packen zu wollen

Manoo 29.01.21 12:07

Das ist mir klar, ich hab das auch mit dem Indicator versucht, weiss aber nicht wie ich das Umseten soll da ich nicht genau durchblicke welchen Wert ich haben soll.
Da es auch noch komplett seperiert ist mit Init Onstart usw kann ich das ja nicht einfach in meinen EA reinkopieren...
:confused:


#property indicator_chart_window
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_buffers 2
double TrendUp[],TrendDown[];
int changeOfTrend;
extern int Nbr_Periods=10;
extern double Multiplier=3.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,TrendUp);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexLabel(0,"Trend Up");
SetIndexBuffer(1,TrendDown);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexLabel(1,"Trend Down");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit,i,flag,flagh,trend[];
double up[],dn[],medianPrice,atr;

int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if(counted_bars==0) limit-=1+1;
//Print(limit);

int xsize=ArraySize(TrendUp);
ArrayResize(trend,xsize);
ArrayResize(up,xsize);
ArrayResize(dn,xsize);
//----
for(i=limit; i>=0; i--)
{
atr=iATR(NULL,0,Nbr_Periods,i);
//Print("atr: "+atr[i]);
medianPrice=(High[i]+Low[i])/2;
//Print("medianPrice: "+medianPrice[i]);
up[i]=medianPrice+(Multiplier*atr);
//Print("up: "+up[i]);
dn[i]=medianPrice-(Multiplier*atr);
//Print("dn: "+dn[i]);
trend[i]=1;

if(Close[i]>up[i+1])
{
trend[i]=1;
if(trend[i+1]==-1) changeOfTrend=1;
//Print("trend: "+trend[i]);

}
else if(Close[i]<dn[i+1])
{
trend[i]=-1;
if(trend[i+1]==1) changeOfTrend=1;
//Print("trend: "+trend[i]);
}
else if(trend[i+1]==1)
{
trend[i]=1;
changeOfTrend=0;
}
else if(trend[i+1]==-1)
{
trend[i]=-1;
changeOfTrend=0;
}

if(trend[i]<0 && trend[i+1]>0)
{
flag=1;
//Print("flag: "+flag);
}
else
{
flag=0;
//Print("flagh: "+flag);
}

if(trend[i]>0 && trend[i+1]<0)
{
flagh=1;
//Print("flagh: "+flagh);
}
else
{
flagh=0;
//Print("flagh: "+flagh);
}

if(trend[i]>0 && dn[i]<dn[i+1])
dn[i]=dn[i+1];

if(trend[i]<0 && up[i]>up[i+1])
up[i]=up[i+1];

if(flag==1)
up[i]=medianPrice+(Multiplier*atr);

if(flagh==1)
dn[i]=medianPrice-(Multiplier*atr);

//-- Draw the indicator
if(trend[i]==1)
{
TrendUp[i]=dn[i];
if(changeOfTrend==1)
{
TrendUp[i+1] = TrendDown[i+1];
changeOfTrend= 0;
}
}
else if(trend[i]==-1)
{
TrendDown[i]=up[i];
if(changeOfTrend==1)
{
TrendDown[i+1]= TrendUp[i+1];
changeOfTrend = 0;
}
}
}

//----
return(0);
}
//+------------------------------------------------------------------+


Alle Zeitangaben in WEZ +2. Es ist jetzt 02:51 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum