新闻中心

新闻中心

当前位置:新闻中心 > 金融文章

追随趋势的思路示范

日期:2018-05-07 发布者:admin 来源:飞碟财经 访问量:813

这只是一个思路示范 使用代码可能会出现严重亏损 仅适用于学习

交易算法的思路 

                     利润交易量的积累使得我们能够从市场变化中获得最大的利润,但是交易量的积累必须避免风险的增加

#property copyright "Copyright © 2008, FXRaider" extern int gap=20;            //level at which arrows are placed extern int TP=400;            //Take Profit level extern int SL=0;              //Stop Loss level extern double Lots1=0.2;      //lot of a main trade extern double Lots2=0.1;      //lot of auxiliary trades extern int slippage=2;        //level of acceptable requote extern int MagicNumber1=5345; //magic number of the main trade extern int MagicNumber2=4365; //magic number of auxiliary trades extern int Open_Step=100;     //step for opening auxiliary trades extern bool UseTrailing = true; //enabling/disabling T-SL extern int TrailingStop = 50;   //Trailing Stop Loss levelextern int TrailingStep = 1;    //Trailing Stop Loss step int start()

  {//------------------------------      //+----------------------------------------------------------------------------------------------+//|                              searching open orders for a pair                                |    intpos_sell=0;   for(inti_op_sell=OrdersTotal()-1; i_op_sell>=0; i_op_sell--)   {   if(!OrderSelect(i_op_sell,SELECT_BY_POS,MODE_TRADES))break;   if(Symbol()==OrderSymbol()    &&OrderMagicNumber()==MagicNumber1      &&(OrderType()==OP_SELL))    {     pos_sell=1;break;      }   }          intpos_buy=0;   for(inti_op_buy=OrdersTotal()-1; i_op_buy>=0; i_op_buy--)   {   if(!OrderSelect(i_op_buy,SELECT_BY_POS,MODE_TRADES))break;   if(Symbol()==OrderSymbol()    &&OrderMagicNumber()==MagicNumber1    &&(OrderType()==OP_BUY))    {     pos_buy=1;break;      }   }    //|                              searching open orders for a pair                                |//+----------------------------------------------------------------------------------------------+  //+------------------------------------------------------------------------------------+//|                                 working with objects                               |  //+----------------------------------------------------------+//|                    deleting objects                      |  if(iBarShift(NULL,0,ObjectGet("down",OBJPROP_TIME1))>0     ||ObjectGet("down",OBJPROP_PRICE1)!=Open[0]-gap*Point)     {     ObjectDelete("down");     }     if(iBarShift(NULL,0,ObjectGet("up",OBJPROP_TIME1))>0    ||ObjectGet("up",OBJPROP_PRICE1)!=Open[0]+gap*Point)                 {     ObjectDelete("up");     }//|                    deleting objects                      |  //+----------------------------------------------------------+//+----------------------------------------------------------+//|                   drawing objects                        |    if((ObjectFind("down") !=0&&ObjectFind("up") !=0)//if no objects   &&!pos_sell&&!pos_buy)                              //if no open orders   {     ObjectCreate("down",OBJ_ARROW,0,Time[0],Open[0]-gap*Point);//draw a down arrow    ObjectSet("down",OBJPROP_STYLE,STYLE_DOT);     ObjectSet("down",OBJPROP_ARROWCODE,234);     ObjectSet("down",OBJPROP_COLOR, Red);     ObjectCreate("up",OBJ_ARROW,0,Time[0],Open[0]+gap*Point);//draw an up arrow    ObjectSet("up",OBJPROP_STYLE,STYLE_DOT);     ObjectSet("up",OBJPROP_ARROWCODE,233);     ObjectSet("up",OBJPROP_COLOR, Blue);    }    //|                   drawing objects                        |//+----------------------------------------------------------+        //|                                 working with objects                               |  //+------------------------------------------------------------------------------------+  //+----------------------------------------------------------------------------------------------+//|                                deleting unnecessary orders                                   |intcnt_del;if(pos_buy==0) {                 for(cnt_del=0; cnt_del<OrdersTotal(); cnt_del++)   {     if(!(OrderSelect(cnt_del,SELECT_BY_POS,MODE_TRADES)))continue;         if(OrderSymbol()==Symbol())     {     if(OrderType()==OP_BUYSTOP&&OrderMagicNumber()==MagicNumber2)OrderDelete(OrderTicket());     }   } }if(pos_sell==0) {                 for(cnt_del=0; cnt_del<OrdersTotal(); cnt_del++)   {     if(!(OrderSelect(cnt_del,SELECT_BY_POS,MODE_TRADES)))continue;         if(OrderSymbol()==Symbol())     {     if(OrderType()==OP_SELLSTOP&&OrderMagicNumber()==MagicNumber2)OrderDelete(OrderTicket());     }   } }  //|                                deleting unnecessary orders                                   |//+----------------------------------------------------------------------------------------------+    //+------------------------------------------------------------------------------------+//|                                   opening trades                                   |doublesl_buy, sl_sell;if(!SL) {   sl_buy=0;   sl_sell=0; }else{   sl_buy=Ask-SL*Point;   sl_sell=Bid+SL*Point; }intstop_positions=MathFloor(TP/Open_Step-1);inti, open_step_2;   if(     ObjectGet("up",OBJPROP_PRICE1)==Open[0]+gap*Point     &&iBarShift(NULL,0,ObjectGet("up",OBJPROP_TIME1))==0     &&ObjectFind("down") !=0     &&ObjectFind("up") ==0     &&!pos_buy        )      {       OrderSend(Symbol(),OP_BUY, Lots1,Ask,slippage,sl_buy,Ask+TP*Point,"take_trend",MagicNumber1,0,Blue);       for(i=stop_positions;i>=0; i--)       {        open_step_2=open_step_2+Open_Step;       OrderSend(Symbol(),OP_BUYSTOP, Lots2,       Ask+open_step_2*Point,slippage,       0,Ask+TP*Point,"take_trend",MagicNumber2,0,Blue);       }                }   if(     ObjectGet("down",OBJPROP_PRICE1)==Open[0]-gap*Point     &&iBarShift(NULL,0,ObjectGet("down",OBJPROP_TIME1))==0     &&ObjectFind("up") !=0     &&ObjectFind("down") ==0     &&!pos_sell      )      {       OrderSend(Symbol(),OP_SELL, Lots1,Bid,slippage,sl_sell,Bid-TP*Point,"take_trend",MagicNumber1,0,Red);       for(i=stop_positions;i>=0; i--)       {        open_step_2=open_step_2+Open_Step;       OrderSend(Symbol(),OP_SELLSTOP, Lots2,       Bid-open_step_2*Point,slippage,       0,Bid-TP*Point,"take_trend",MagicNumber2,0,Red);       }              }//|                                   opening trades                                   |  //+------------------------------------------------------------------------------------+  //+-------------------------------------------------------------------------------------------------+//|                                      trail of open orders                                       |if(UseTrailing) {   for(inttrall=0; trall<OrdersTotal(); trall++) {     if(!(OrderSelect(trall,SELECT_BY_POS,MODE_TRADES)))continue;     if(OrderSymbol() !=Symbol())continue;           if(OrderType() ==OP_BUY) {       if(Bid-OrderOpenPrice() > TrailingStop*Point||OrderMagicNumber()==MagicNumber2) {         if(OrderStopLoss() <Bid-(TrailingStop+TrailingStep-1)*Point||OrderStopLoss() ==0) {           OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0, Blue);        }       }     }     if(OrderType() ==OP_SELL) {     if(OrderOpenPrice()-Ask> TrailingStop*Point||OrderMagicNumber()==MagicNumber2) {         if(OrderStopLoss() >Ask+(TrailingStop+TrailingStep-1)*Point||OrderStopLoss() ==0) {           OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0, Blue);         }      }     }   } }//|                                      trail of open orders                                       |//+-------------------------------------------------------------------------------------------------+       return(0);   }//+------------------------------------------------------------------+代码包含所有必要的注释。

变量:

gap – level, on which arrows are placed;

TP – Take Profit level; SL – Stop Loss level; Lots1 – lot of a main trade; Lots2 – lot of auxiliary trades; slippage – level of acceptable requote; MagicNumber1 – magic number of the main trade; MagicNumber2 – magic number of auxiliary trades; Open_Step – step for opening auxiliary trades; UseTrailing – enabling/disabling T-SL; TrailingStop – Trailing Stop Loss level; TrailingStep – Trailing Stop Loss step.

飞碟财经
   发布时间: 2018-05-07 04:50:33
获利交易的成交量积累可以让我们从市场变动中最大化获利。但成交量积累必须避免导致风险的增加。本文描述了这种成交量积累的算法之一。 首先,我们需要一个参考点 - 第一个主交易。主交易的交易量应大于每个辅交易的交易量。假设主交易的量为 0.2 手,辅交易的量则为 0.1 手。跟踪止损用于所有的交易,例如,50 个点。当主交易的获利达到 +100 点,止损为 +50。此时,在止损 -50 点的相同方向上打开 0.1 手的交易。如果价格回落,两个交易将被止损订单关闭。获得的利润等于 0.2 手的 50 点和 0.1 手的 - 50 点。总共获利等于 0.1 手的 50 点。这样就在交易量增加时实现了止损保护。 如果交易继续沿着必要的方向移动,当辅交易的获利达到 +50 点时,跟踪止损激活。当主交易的获利达到 200 点,辅交易的获利达到 100 点,将打开另一个辅交易。止损还是等于 -50。诸如此类。 这是一个非常简单的从手数积累良好获利的方法。同时使风险最小化。实际上,这里的风险不过是亏损了主交易的一部分,即第一个辅交易亏损的风险。但这并不是亏损风险,而是没有获得全部利润的风险。 标准的跟踪 止 损在只有获利时才跟踪交易。但如果在获得必要的利润之前对辅交易实施,则可以提高这种手数积累方法的获利性。你可以利用 MQL4 在优化辅订单的打开时如此操作。
 


   发布时间: 2018-12-29 01:27:36
!S!WCRTESTTEXTAREA000000!E!
 
    我要评论
    评论内容:

    上一篇: 网页版MT4 代码示例

    下一篇: 区块链词汇表