如何编码? - 页 186

 

好的,关于最初的问题。

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Magenta

extern int MAPeriod=200;

extern double iController = 1.386;

//---- buffers

//double Memory[200];

double ExtMapBuffer1[];

int limit = 200;

//---- variables

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

//| Custom indicator initialization function |

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

int init()

{

IndicatorBuffers(1);

//---- drawing settings

SetIndexBuffer(0,ExtMapBuffer1);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);

IndicatorShortName( "Antaria_Rising");

//---- initialization done

return(0);

}

int start()

{

int limit;

//ExtMapBuffer1[1] = ExtMapBuffer1[0];

//ExtMapBuffer1[0] = iController;

for(int i=(0); i<=(limit-1); i++)

{

ExtMapBuffer1 = ExtMapBuffer1;

}

ExtMapBuffer1[0] = iController;

return(0);

}[/CODE]

Above is the code for the indicator. Simply, it draws a line that should be updatable via the EA using the intiially mentioned code:

[CODE]temp = iCustom(NULL, 0, "AntariaRising", 200, 1.2, 0, 0); //temp not used. Function returns a double

我想,我想替换最后一段代码,它实际上允许我将其跟踪的变量更新到incicator对象中,这样我就可以在以后将它作为一个停止线使用。然而,其余的代码是不相关的。当我运行上述函数 时,我希望antaria将位置从1.39或任何它开始的位置移动到1.2。我不记得我是否使用了200这个变量。我想我已经砍掉了我的页眉和页脚注释,但整个从属指标都在上面,这就是上面代码中提到的AntariaRising。

这是我能找到的唯一与指标对象对话的函数,我用它来读出其他区域的值。

 

关于你的指标代码。它是错误的。

Var.极限值永远等于零。

拿掉这个字符串。

int limit。

从start()中删除。

 

请帮助我处理这个代码

我希望有人能帮助我处理这段代码,它在我想要的时候打开交易,但又自动关闭,所以我希望它在交易时有止损,而不是在不交叉时关闭,这就是代码。

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

//| JR300.mq4 |

外汇论坛|外汇Tsd|Metatrader论坛|//|外汇论坛

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

#财产版权 "oneLove"

#属性链接 "https://www.forex-tsd.com"

//---- 输入参数

extern double TakeProfit=250.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

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

//|专家初始化函数 |

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

int init()

{

//----

//----

return(0);

}

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

//|专家的去初始化功能|

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

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(line1>line2)current_direction = 1; //向上

如果(line1<line2)current_direction = 2; //向下

如果(current_direction != last_direction) //改变了

{

last_direction = current_direction;

return (last_direction);

}

否则

{

返回(0)。

}

}

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

//|专家启动功能|

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

int start()

{

//----

int cnt, ticket, total;

双短Ema, 长Ema。

如果(Bars<100)

{

Print("小于100的条数")。

return(0);

}

如果(TakeProfit<10)

{

Print("TakeProfit小于10")。

return(0); // 检查TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0)。

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0)。

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

如果(isCrossed == 1)

{

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

"My EA",12345,0,Green)。

如果(ticket>0)

{

如果(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

Print("BUY order opened : ",OrderOpenPrice());

}

否则 Print("打开BUY订单错误。",GetLastError())。

return(0);

}

如果(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,

Bid-TakeProfit*Point, "My EA",12345,0,Red)。

如果(ticket>0)

{

如果(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

Print("Sell order opened : ",OrderOpenPrice());

}

否则 Print("打开卖出订单错误。",GetLastError())。

return(0);

}

return(0);

}

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)。

如果(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

如果(OrderType()==OP_BUY)// 多头头寸被打开

{

//应该平仓吗?

如果(isCrossed == 2)

{

OrderClose(OrderTicket(),OrderLots(), Bid,3,Violet)。

//平仓

return(0); // 退出

}

// 检查拖曳止损

如果(TrailingStop>0)

{

如果(Bid-OrderOpenPrice()>Point*TrailingStop)

{

如果(OrderStopLoss()<Bid-Point*TrailingStop))

{

OrderModify(OrderTicket(),OrderOpenPrice(), Bid-

Point*TrailingStop,OrderTakeProfit(),0,Green)。

返回(0)。

}

}

}

}

否则 // 转入空头头寸

{

//应该平仓吗?

如果(isCrossed == 1)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet)。

//平仓

return(0); // 退出

}

// 检查拖曳止损

如果(TrailingStop>0)

{

如果((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

如果((OrderStopLoss()>(Ask+Point*TrailingStop))||

(OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,

OrderTakeProfit(),0,Red)。

返回(0)。

}

}

}

}

}

}

return(0);

}

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

 

试试这个。

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

//| JR300.mq4 |

//| onelove |

//| Forex Forum | Forex Tsd | Metatrader Forum |

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

#property copyright "oneLove"

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

//---- input parameters

extern double TakeProfit=250.0;

extern double StopLoss=100.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

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

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

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

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

//| expert start function |

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

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+ TakeProfit*Point,

"My EA",12345,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());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,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());

return(0);

}

return(0);

}

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

{

// should it be closed?

//if(isCrossed == 2)

//{

//OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ;

// close position

//return(0); // exit

//}

// 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

{

// should it be closed?

//if(isCrossed == 1)

//{

//OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ;

// close position

//return(0); // exit

//}

// 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);

}

}

}

}

}

}

return(0);

}

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

谢谢

Roger09:
试试这个。
//+------------------------------------------------------------------+

//| JR300.mq4 |

//| onelove |

//| Forex Forum | Forex Tsd | Metatrader Forum |

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

#property copyright "oneLove"

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

//---- input parameters

extern double TakeProfit=250.0;

extern double StopLoss=100.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

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

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

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

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

//| expert start function |

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

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+ TakeProfit*Point,

"My EA",12345,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());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,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());

return(0);

}

return(0);

}

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

{

// should it be closed?

//if(isCrossed == 2)

//{

//OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ;

// close position

//return(0); // exit

//}

// 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

{

// should it be closed?

//if(isCrossed == 1)

//{

//OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ;

// close position

//return(0); // exit

//}

// 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);

}

}

}

}

}

}

return(0);

}

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

谢谢 roger09 上帝保佑你

 

谢谢你,我已经从我的启动函数 中删除了第二个极限声明。我很惊讶编译器允许这个声明,但它对我的程序没有明显的影响。

但我还是不确定如何从我的EA中改变该指标的运行实例。如果有方法,我将非常感激,或者至少确认API目前不允许我向运行中的指标传递信息。

谢谢。

 
yingli:
我开始这个帖子是为了得到一些帮助。我正在学习所附指标的代码,但它没有成功。有人能帮助吗?这是一个非常可靠的指标,如果有人能为它制作一个EA,这几乎是一个圣杯。

基本原则是。

1.当红色箭头出现时打开卖出头寸。

2.当白色箭头出现时,打开买入头寸,并自动关闭所有卖出头寸/位置。

3.适用于任何时间框架。

4.没有止损。

5.添加订单功能。

期待您的回复!

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

//| IINWMARROWS.mq4|

//|基于EMA_CROSS.mq4 |/|

//| Copyright ?2006, MetaQuotes Software Corp.|

//|外汇交易软件。外汇交易平台MetaTrader 4

//| 最后一点修改:Iin Zulkarnain |/|

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

#property copyright "Copyright ?2006, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

//----

#属性 indicator_chart_window

#属性 indicator_buffers 2

#属性 indicator_color1 White

#属性 indicator_color2 红色

#属性 indicator_width1 2

#perty indicator_width2 2

//----

double CrossUp[];

double CrossDown[];

extern int FasterMode=3; //0=sma, 1=ema, 2=smma, 3=lwma

extern int FasterMA=3;

Extern int SlowerMode=3; //0=sma, 1=ema, 2=smma, 3=lwma

外置int SlowerMA= 3;

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

//|自定义指标初始化函数

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

int init()

{

//---- 指标

SetIndexStyle(0, DRAW_ARROW, EMPTY);

SetIndexArrow(0, 233);

SetIndexBuffer(0, CrossUp);

SetIndexStyle(1, DRAW_ARROW, EMPTY);

SetIndexArrow(1, 234);

SetIndexBuffer(1, CrossDown)。

//----

return(0);

}

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

//|自定义指标去初始化函数|

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

int deinit()

{

//----

//----

return(0);

}

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

//|自定义指标迭代函数|

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

int start()

{

int limit, i, counter;

double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;

双重Range, AvgRange;

int counted_bars=IndicatorCounted()。

//----,检查可能的错误

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

//---- 最后一个被计算的柱子将被重新计算。

如果(counted_bars>0) counted_bars--。

//----

limit=Bars-counted_bars。

for(i=0; i<=limit; i++)

{

counter=i;

范围=0。

平均范围=0。

for(counter=i ;counter<=i+9; counter++)

{

AvgRange=AvgRange+MathAbs(High[counter]-Low[counter])。

}

Range=AvgRange/10。

fasterMAnow=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i)。

fasterMAprevious=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);

fasterMAafter=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1)。

//----

slowerMAnow=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i);

slowerMAprevious=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+1);

slowerMAafter=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1)。

如果((fasterMAnow > slowerMAnow) && (fasterMAprevious slowerMAafter))

{

CrossUp=Low - Range*0.5。

}

否则如果((fasterMAnow slowerMAprevious) && (fasterMAafter < slowerMAafter))

{

CrossDown=High + Range*0.5;

}

}

返回(0)。

}

//+------------------------------------------------------------------+这个主题是为了学习如何正确编码,我正在学习编码。

有谁能帮助为这个指标编写一个警报代码,它真的很酷。

 

乔治的奥斯卡计算器--谁能为它编写一个指标?

嗨,伙计们。

我不知道是否有人熟悉乔治-史密斯的Forex Made-EZ。

我目前正在审查他的工作,想知道是否有人为他使用的奥斯卡振荡器编码了一个指标?

其公式为

让A=过去8个柱子(包括这个)的最高点

让B = 过去八个柱子(包括这一个)中的最低点

让C = 当前条形图的收盘价

让X =之前的振荡器数字(奥斯卡)。

今天的 "粗略 "震荡指标等于(C-B)除以(A-B)乘以100。

接下来我们 "平滑 "我们的粗略数字(让我们称之为Y),像这样。

最终振荡器的数量=((X除以3)乘以2),加上(Y除以3)。

如果有人编过这样的代码或能编出这样的代码,我们将非常感激。

谢谢你,史蒂夫

 

倒置的追踪止损

你好。

我想在一个想法上得到一些帮助。

我在我的EA中使用追踪止损(3步追踪),但我想做倒置的事情来保护损失。

我试着解释一下。

我开了一个订单,有一个初始止损

如果交易向亏损方向移动了15个点,但又回来了10个点,就关闭交易(第一步)。

如果交易向亏损方向移动了30点,又回来了15点,就关闭交易(第二步)。

类似这样的情况。

谢谢你的帮助

 
dedreko:
你好。

我想在一个想法上得到一些帮助。

我在我的EA上使用追踪止损(3步追踪),但我想做倒置的事情来保护损失。

我试着解释一下。

我开了一个订单,有一个初始止损。

如果交易向亏损方向移动了15个点,但又回来了10个点,就关闭交易(第一步)。

如果交易向亏损方向移动了30个点,又回来了15个点,就关闭交易(第二步)。

类似这样的情况。

谢谢你的帮助

这对我来说是件新鲜事。

那么,关闭亏损的交易总是需要等待它反弹,对吗?

如果它不反弹呢?

我们会在最初的SL上平仓吗?

原因: