有您的持续关注
我们会做得更好

智能交易系统纵横汇海ECNEA



纵横汇海ECNEA属于那种在ECN低点差模式下剥头皮类型,曾经淘宝有人出售且售价不菲。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。 纵横汇海ECNEA源码如下:

//+------------------------------------------------------------------+
//|                                                纵横汇海ECNEA.mq4 |
//|                                       Copyright @2016, 125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com"

#property show_inputs

#include <stdlib.mqh>

//----------------------- Externals ----------------------------------------------------------------
// All externals here have their name starting with a CAPITAL character

extern string Configuration = "==== Configuration ====";
extern int Magic = 0;
extern string OrderCmt = "";
extern bool NDDmode = TRUE;
extern bool Show_Debug = FALSE;
extern bool Verbose = FALSE;
extern string ScalpingSettings = "==== Scalping settings ====";
extern double TakeProfit = 20.0;
extern double StopLoss = 60.0;
extern double Trailing_Start = 2;
extern double VolatilityLimit = 130;        // Default 250. Can normally be between 100 and 300
extern double Scalpfactor = 66;                // 60 to 77 - only used if larger than broker StopLevel
extern bool UseMovingAverage = FALSE;      // User two iMA as channell
extern bool UseBollingerBands = TRUE;      // Use iBands as channel
extern int IndicatorPeriod = 30;          // Period for iMA and iBands
extern int OrderExpireSeconds = 3600;        // Orders are deted after so many seconds
extern string Money_Management = "==== Money Management ====";
extern double Min_Lots = 0.01;
extern double Max_Lots = 100.0;
extern double Risk = 100.0;

//--------------------------- Globals --------------------------------------------------------------
// All globals have their name written in lower case characters
// 

bool condition1;
bool condition2 = FALSE;
bool trailingstop = TRUE;

int distance = 0;
int brokerdigits = 0;
int slippage = 3;
int array_tickcounts[30];
int globalerror = 0;
int lasttime = 0;
int tickcounter = 0;
int upto30counter = 0;
int AccNum;

double zero = 0.0;
double zeropointfour = 0.4;
double one = 1.0;
double five = 5.0;
double ten = 10.0;
double twenty = 20.0;
double forty = 40.0;
double multiplier;
double commission = 0.0;
double minmaxlot = 0.1;
double maxamount = 0.0;
double pipette = 0.0;
double upper;
double lower;
double array_bid[30];
double array_ask[30];
double array_spread[30];

//======================= Program initialization ===========================================================

int init() 
{
   int stoplevel;

   ArrayInitialize(array_spread, 0);
    VolatilityLimit = VolatilityLimit * Point;
   Scalpfactor = Scalpfactor * 10 * Point / 3; 
   brokerdigits = Digits;
   pipette = Point; 
   
      stoplevel = MathMax(MarketInfo(Symbol(), MODE_FREEZELEVEL), MarketInfo(Symbol(), MODE_STOPLEVEL));
    if (TakeProfit < stoplevel)
        TakeProfit = stoplevel;
    if (StopLoss < stoplevel)
        StopLoss = stoplevel;
    if (distance < stoplevel)
        distance = stoplevel;
   
    if (MathMod(Digits, 2) == 0) 
        slippage = 0;
   else 
        globalerror = -1;
   
   start();
   return (0);
}

//====================== Program start ===================================

int start() 
{
   for(int i = 0; i < OrdersTotal(); i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
        if(OrderType() == OP_BUY && (OrderStopLoss() == 0 || OrderTakeProfit() == 0)) {
          OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - StopLoss*Point,OrderOpenPrice() + 
TakeProfit*Point,0,Yellow);
          }
        if(OrderType() == OP_SELL && (OrderStopLoss() == 0 || OrderTakeProfit() == 0)) {
          OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + StopLoss*Point,OrderOpenPrice() - 
TakeProfit*Point,0,Yellow);
         }
      }
   }
   
   
   if (brokerdigits == 0) 
    {
      init();
      return;
   }

    sub_trade();
   return (0);
}

//===================== Subroutines starts here =========================================
// All subs have their names starting with sub_
// Exception are the standard routines init() and start()
//
// Notation:
// All parameters in subs have their names starting with par_
// All local variables in subs have thewir names starting with local_
//

void sub_trade() 
{
   string local_textstring;
    
   bool local_wasordermodified;
   bool local_highspeed;
    bool local_ordersenderror;    
    bool local_isbidgreaterthanima;      
    bool local_isbidgreaterthanibands;
    bool local_isbidgreaterthanindy;

   int local_orderticket;
   int local_lotstep;
   int local_orderexpiretime;   
   int local_bidpart;
   int local_askpart;
    int local_loopcount2;    
    int local_loopcount1;    
    int local_pricedirection;    
   int local_counter1;
   int local_counter2;    

   double local_askplusdistance;
   double local_bidminusdistance;
   double local_a;
   double local_b;
   double local_c;
   double local_scalpsize;    
   double local_d;
   double local_orderstoploss;
   double local_ordertakeprofit;
   double local_tpadjust;
    double local_ihigh;    
   double local_ilow;    
    double local_imalow;    
   double local_imahigh;
   double local_imadiff;
   double local_ibandsupper;
   double local_ibandslower;    
   double local_ibandsdiff;
   double local_highest;
   double local_lowest;
    double local_stoplevel;
   double local_spread;
   double local_adjuststoplevel;
    double local_e;    
   double local_avgspread;    
    double local_f;
   double local_g;
   double local_h;
   double local_ihighilowdiff;
    double local_i;    
    
   if (lasttime < Time[0]) 
    {
      lasttime = Time[0];
      tickcounter = 0;
   } 
    else 
        tickcounter++;
   
    // Calculate a channel based on some indicators
    local_ihigh = iHigh(Symbol(), PERIOD_M1, 0);
   local_ilow = iLow(Symbol(), PERIOD_M1, 0);
   local_ihighilowdiff = local_ihigh - local_ilow;  
   
    local_imalow = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_LOW, 0);
   local_imahigh = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_HIGH, 0);
   local_imadiff = local_imahigh - local_imalow;
   local_isbidgreaterthanima = Bid >= local_imalow + local_imadiff / 2;  
    
   local_ibandsupper = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, 2.0, MODE_UPPER, 0);
   local_ibandslower = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, 2.0, MODE_LOWER, 0);
    local_ibandsdiff = local_ibandsupper - local_ibandslower;
    local_isbidgreaterthanibands = Bid >= local_ibandslower + local_ibandsdiff / 2;
    
    // local_isbidgreaterthanindy is only used for OrderModify on previous BUY_STOP and SELL_STOP
    local_isbidgreaterthanindy = FALSE;
    if (UseMovingAverage == FALSE && UseBollingerBands == TRUE)
    {
        local_isbidgreaterthanindy = TRUE;
      local_highest = local_ibandsupper;
      local_lowest = local_ibandslower; 
    }
    else if (UseMovingAverage == TRUE && UseBollingerBands == FALSE)
    {
        local_isbidgreaterthanindy = TRUE; 
      local_highest = local_imahigh;
      local_lowest = local_imalow;    
    }
    else if (UseMovingAverage == TRUE && UseBollingerBands == TRUE)
        if (local_isbidgreaterthanima == TRUE && local_isbidgreaterthanibands == TRUE)
        {
            local_isbidgreaterthanindy = TRUE;
         local_highest = MathMax(local_ibandsupper, local_imahigh);
         local_lowest = MathMin(local_ibandslower, local_imalow);
      }
    
    if (!condition2) 
    {
      for (local_loopcount2 = OrdersTotal() - 1; local_loopcount2 >= 0; local_loopcount2--) 
        {
         OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() && 
OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1 &&
            StringFind(OrderComment(), "[tp]from #") == -1) 
            {
            condition2 = TRUE;
            local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice()));
            commission = (-OrderCommission()) / local_a;
            Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission));
            break;
         }
      }
   }
    
   if (!condition2) 
    {
      for (local_loopcount2 = OrdersHistoryTotal() - 1; local_loopcount2 >= 0; local_loopcount2--) 
        {
         OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_HISTORY);
         if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() && 
OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1 
            && StringFind(OrderComment(), "[tp]from #") == -1) 
            {
            condition2 = TRUE;
            local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice()));
            commission = (-OrderCommission()) / local_a;
            Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission));
            break;
         }
      }
   }
    
   local_stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
   local_spread = Ask - Bid;
   local_adjuststoplevel = 0.5;
   if (local_adjuststoplevel < local_stoplevel - 5.0 * pipette) 
    {
      local_highspeed = FALSE;
      local_b = forty * pipette;
      local_adjuststoplevel = ten * pipette;
      local_c = five * pipette;
   } 
    else 
    {
      local_highspeed = TRUE;
      local_b = twenty * pipette;
      local_adjuststoplevel = zero * pipette;
      local_c = Trailing_Start * pipette;
   }
    
   local_b = MathMax(local_b, local_stoplevel);
   if (local_highspeed) 
        local_adjuststoplevel = MathMax(local_adjuststoplevel, local_stoplevel); 
   ArrayCopy(array_spread, array_spread, 0, 1, 29);
   array_spread[29] = local_spread;
   if (upto30counter < 30) 
        upto30counter++;
   local_e = 0;
   local_loopcount2 = 29;
   for (local_loopcount1 = 0; local_loopcount1 < upto30counter; local_loopcount1++) 
    {
      local_e += array_spread[local_loopcount2];
      local_loopcount2--;
   }
    
   local_avgspread = local_e / upto30counter;
   if (!condition2 && local_avgspread < 15.0 * pipette) 
        commission = 15.0 * pipette - local_avgspread;
   
    local_f = sub_normalizebrokerdigits(Ask + commission);
   local_g = sub_normalizebrokerdigits(Bid - commission);
   local_h = local_avgspread + commission;

   if(local_ihighilowdiff > VolatilityLimit) 
    { 
        if (Bid < local_lowest)                
            local_pricedirection = -1; 
        else if (Bid > local_highest)        
            local_pricedirection = 1;
   }    
   
    local_scalpsize = MathMax(local_stoplevel, Scalpfactor);
     
    if (Bid == 0.0 || MarketInfo(Symbol(), MODE_LOTSIZE) == 0.0) 
        local_scalpsize = 0;
   
    local_i = local_scalpsize + local_avgspread + commission;
   local_orderexpiretime = TimeCurrent() + OrderExpireSeconds;   
   
    if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.0) 
        local_lotstep = 5;
   else 
        local_lotstep = sub_logarithm(0.1, MarketInfo(Symbol(), MODE_LOTSTEP));
   
    if (Risk < 0.001 || Risk > 1000.0) 
    {
      Comment("ERROR -- Invalid Risk Value.");
      return;
   }
   
    if (AccountBalance() <= 0.0) 
    {
      Comment("ERROR -- Account Balance is " + DoubleToStr(MathRound(AccountBalance()), 0));
      return;
   }
   
   if (local_scalpsize != 0.0) 
    {
      maxamount = MathMax(AccountBalance(), maxamount);
      local_d = MathMin(AccountFreeMargin() * AccountLeverage() / 2.0, maxamount * Risk / 100.0 * Bid / local_i);
      minmaxlot = local_d / MarketInfo(Symbol(), MODE_LOTSIZE);
      minmaxlot = NormalizeDouble(minmaxlot, local_lotstep);
      minmaxlot = MathMax(Min_Lots, minmaxlot);
      minmaxlot = MathMax(MarketInfo(Symbol(), MODE_MINLOT), minmaxlot);
      minmaxlot = MathMin(Max_Lots, minmaxlot);
      minmaxlot = MathMin(MarketInfo(Symbol(), MODE_MAXLOT), minmaxlot);
   }
    
    // Run through already open orders and modify if necessary
   local_counter1 = 0;
   local_counter2 = 0;
   for (local_loopcount2 = 0; local_loopcount2 < OrdersTotal(); local_loopcount2++) 
    {
      OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == Magic && OrderCloseTime() == 0) 
        {
         if (OrderSymbol() != Symbol()) 
            {
            local_counter2++;
            continue;
         }
         switch (OrderType()) 
            {
         case OP_BUY:
            while (trailingstop) 
                {
               local_orderstoploss = OrderStopLoss();
               local_ordertakeprofit = OrderTakeProfit();
               if (!(local_ordertakeprofit < sub_normalizebrokerdigits(local_f + local_b) && 
local_f + local_b - local_ordertakeprofit > local_c)) 
                        break;
               local_orderstoploss = sub_normalizebrokerdigits(Bid - local_b);
               local_ordertakeprofit = sub_normalizebrokerdigits(local_f + local_b);
               local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss, 
local_ordertakeprofit, local_orderexpiretime, Lime);
                    break;
            }
            local_counter1++;
            break;
         case OP_SELL:
            while (trailingstop) 
                {
               local_orderstoploss = OrderStopLoss();
               local_ordertakeprofit = OrderTakeProfit();
               if (!(local_ordertakeprofit > sub_normalizebrokerdigits(local_g - local_b) && 
local_ordertakeprofit - local_g + local_b > local_c)) 
                        break;
               local_orderstoploss = sub_normalizebrokerdigits(Ask + local_b);
               local_ordertakeprofit = sub_normalizebrokerdigits(local_g - local_b);
               local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss, 
local_ordertakeprofit, local_orderexpiretime, Orange);
               break;
            }
            local_counter1++;
            break;
         case OP_BUYSTOP:
            if (!local_isbidgreaterthanindy) 
                {
               local_tpadjust = OrderTakeProfit() - OrderOpenPrice() - commission;
               while (true) 
                    {
                  if (!(sub_normalizebrokerdigits(Ask + local_adjuststoplevel) < OrderOpenPrice() && 
OrderOpenPrice() - Ask - local_adjuststoplevel > local_c)) 
                            break;
                  local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Ask + 
local_adjuststoplevel), sub_normalizebrokerdigits(Bid + local_adjuststoplevel - local_tpadjust), 
sub_normalizebrokerdigits(local_f + local_adjuststoplevel + local_tpadjust), 0, Lime);
                  break;
               }
               local_counter1++;
            } 
                else 
                    OrderDelete(OrderTicket());
            break;
         case OP_SELLSTOP:
            if (local_isbidgreaterthanindy) 
                {
               local_tpadjust = OrderOpenPrice() - OrderTakeProfit() - commission;
               while (true) 
                    {
                  if (!(sub_normalizebrokerdigits(Bid - local_adjuststoplevel) > OrderOpenPrice() &&
 Bid - local_adjuststoplevel - OrderOpenPrice() > local_c)) 
                            break;
                  local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Bid - 
local_adjuststoplevel), sub_normalizebrokerdigits(Ask - local_adjuststoplevel + local_tpadjust), 
sub_normalizebrokerdigits(local_g - local_adjuststoplevel - local_tpadjust), 0, Orange);
                  break;
               }
               local_counter1++;
            } 
                else 
                    OrderDelete(OrderTicket());
         }
      }
   }
   
   local_ordersenderror = FALSE;
   if (globalerror >= 0 || globalerror == -2) 
    {
      local_bidpart = NormalizeDouble(Bid / pipette, 0);
      local_askpart = NormalizeDouble(Ask / pipette, 0);
      if (local_bidpart % 10 != 0 || local_askpart % 10 != 0) 
            globalerror = -1;
      else 
        {
         if (globalerror >= 0 && globalerror < 10) 
                globalerror++;
         else 
                globalerror = -2;
      }
   }
   
    // Open new BUY- or SELL-orders, or BUYSTOP or SELLSTOP orders
   if (local_scalpsize != 0.0 && local_counter1 == 0 && local_pricedirection != 0 && 
sub_normalizebrokerdigits(local_h) <= sub_normalizebrokerdigits(forty * pipette) && globalerror == -1) 
    {
      if (local_pricedirection < 0) 
        {
         if (local_highspeed) 
            {
                local_askplusdistance = Ask + distance * Point;
            if (NDDmode)
            {
                    local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, 
slippage, 0, 0, OrderCmt, Magic, 0, Lime);             
                    if (OrderSelect(local_orderticket, SELECT_BY_TICKET)) 
                        OrderModify(OrderTicket(), OrderOpenPrice(), local_askplusdistance - StopLoss * Point, 
local_askplusdistance + TakeProfit * Point, local_orderexpiretime, Lime);
            } 
            else 
                    local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, 
slippage, local_askplusdistance - StopLoss * Point, local_askplusdistance + TakeProfit * Point, OrderCmt, 
Magic, local_orderexpiretime, Lime);
            
                if (local_orderticket < 0) 
                {
               local_ordersenderror = TRUE;
               Print("ERROR BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" + 
sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" + 
sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize));
            } 
                else 
                {
               PlaySound("news.wav");
               Print("BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" + 
sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" + 
sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize));
            }
         } 
            else // local_highspeed == FALSE
            {
            if (Bid - local_ilow > 0.0) 
                {
               local_orderticket = OrderSend(Symbol(), OP_BUY, minmaxlot, Ask, slippage, 0, 0, OrderCmt,
 Magic, local_orderexpiretime, Lime);
               if (local_orderticket < 0) 
                    {
                  local_ordersenderror = TRUE;
                  Print("ERROR BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + 
sub_dbl2strbrokerdigits(Bid - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize));
               } 
                    else 
                    {
                  while (true) 
                        {
                     local_wasordermodified = OrderModify(local_orderticket, 0, 
sub_normalizebrokerdigits(Bid - local_scalpsize), sub_normalizebrokerdigits(local_f + local_scalpsize), 
local_orderexpiretime, Lime);
                     break;
                  }
                  PlaySound("news.wav");
                  Print("BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + 
sub_dbl2strbrokerdigits(Bid - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize));
               }
            }
         }
      } 
        else 
        {
         if (local_pricedirection > 0) 
            {
            if (local_highspeed) 
                {
            local_bidminusdistance = Bid - distance * Point;
               if (NDDmode)
               {
                        local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance, 
slippage, 0, 0, OrderCmt, Magic, 0, Orange);                
                        if (OrderSelect(local_orderticket, SELECT_BY_TICKET)) 
                            OrderModify(OrderTicket(), OrderOpenPrice(), local_bidminusdistance + 
StopLoss * Point, local_bidminusdistance - TakeProfit * Point, local_orderexpiretime, Orange);
               }
               else 
                        local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance, 
slippage, local_bidminusdistance + StopLoss * Point, local_bidminusdistance - TakeProfit * Point, OrderCmt, 
Magic, local_orderexpiretime, Orange);
               if (local_orderticket < 0) 
                    {
                  local_ordersenderror = TRUE;
                  Print("ERROR SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" + 
sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" + 
sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize));
               } 
                    else 
                    {
                  PlaySound("news.wav");
                  Print("SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" + 
sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" + 
sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize));
               }
            } 
                else // local_highspeed == FALSE
                {
               if (local_ihigh - Bid  < 0.0) 
                    {
                  local_orderticket = OrderSend(Symbol(), OP_SELL, minmaxlot, Bid, slippage, 0, 0, 
OrderCmt, Magic, local_orderexpiretime, Orange);
                  if (local_orderticket < 0) 
                        {
                     local_ordersenderror = TRUE;
                     Print("ERROR SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" + 
sub_dbl2strbrokerdigits(Ask + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize));
                  } 
                        else 
                        {
                     while (true) 
                            {
                        local_wasordermodified = OrderModify(local_orderticket, 0, 
sub_normalizebrokerdigits(Ask + local_scalpsize), sub_normalizebrokerdigits(local_g - local_scalpsize), 
local_orderexpiretime, Orange);
                        break;
                     }
                     PlaySound("news.wav");
                     Print("SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" + 
sub_dbl2strbrokerdigits(Ask + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize));
                  }
               }
            }
         }
      }
   }
   
   if (globalerror >= 0) 
        Comment("Robot is initializing...");
   else 
    {
      if (globalerror == -2) 
            Comment("ERROR -- Instrument " + Symbol() + " prices should have " + brokerdigits + 
" fraction digits on broker account");
      else 
        {
         local_textstring = TimeToStr(TimeCurrent()) + " tick:" + sub_adjust00instring(tickcounter);
         if (Show_Debug || Verbose) 
            {
            local_textstring = local_textstring + "\n" + sub_dbl2strbrokerdigits(Scalpfactor) + "
 " + sub_dbl2strbrokerdigits(local_scalpsize) + " digits:" + brokerdigits + " " + globalerror + " stopLevel:" + 
sub_dbl2strbrokerdigits(local_stoplevel);
            local_textstring = local_textstring + "\n" + local_pricedirection + " 
" + sub_dbl2strbrokerdigits(local_imahigh) + " " + sub_dbl2strbrokerdigits(local_imalow) + " 
" + sub_dbl2strbrokerdigits(zeropointfour) + " exp:" + TimeToStr(local_orderexpiretime, TIME_MINUTES) + 
" numOrders:" + local_counter1 + " shouldRepeat:" + local_ordersenderror;
            local_textstring = local_textstring + "\ntrailingLimit:" + 
sub_dbl2strbrokerdigits(local_adjuststoplevel) + " trailingDist:" + sub_dbl2strbrokerdigits(local_b) + 
" trailingResolution:" + sub_dbl2strbrokerdigits(local_c) + " useStopOrders:" + local_highspeed;
         }
         local_textstring = local_textstring + "\nBid:" + sub_dbl2strbrokerdigits(Bid) + " Ask:" + 
sub_dbl2strbrokerdigits(Ask) + " avgSpread:" + sub_dbl2strbrokerdigits(local_avgspread) + "  Commission rate:" + 
sub_dbl2strbrokerdigits(commission) + "  Real avg. spread:" + sub_dbl2strbrokerdigits(local_h) + "  Lots:" + 
sub_dbl2strparb(minmaxlot, local_lotstep);
         if (sub_normalizebrokerdigits(local_h) > sub_normalizebrokerdigits(forty * pipette)) 
            {
            local_textstring = local_textstring + "\n" + "Robot is OFF :: Real avg. spread is too high for 
this scalping strategy ( " + sub_dbl2strbrokerdigits(local_h) + " > " + 
sub_dbl2strbrokerdigits(forty * pipette) + " )";
         }
         Comment(local_textstring);
         if (local_counter1 != 0 || local_pricedirection != 0 || Verbose) 
                sub_printformattedstring(local_textstring);
      }
   }
}

string sub_dbl2strbrokerdigits(double par_a) 
{
   return (DoubleToStr(par_a, brokerdigits));
}

string sub_dbl2strparb(double par_a, int par_b) 
{
   return (DoubleToStr(par_a, par_b));
}

double sub_normalizebrokerdigits(double par_a) 
{
   return (NormalizeDouble(par_a, brokerdigits));
}

string sub_adjust00instring(int par_a) 
{
   if (par_a < 10) 
        return ("00" + par_a);
   if (par_a < 100) 
        return ("0" + par_a);
   return ("" + par_a);
}

double sub_logarithm(double par_a, double par_b) 
{
   return (MathLog(par_b) / MathLog(par_a));
}

void sub_printformattedstring(string par_a) 
{
   int local_difference;
   int local_a = -1;

   while (local_a < StringLen(par_a)) 
    {
      local_difference = local_a + 1;
      local_a = StringFind(par_a, "\n", local_difference);
      if (local_a == -1) 
        {
         Print(StringSubstr(par_a, local_difference));
         return;
      }
      Print(StringSubstr(par_a, local_difference, local_a - local_difference));
   }
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 智能交易系统纵横汇海ECNEA
上一篇:
下一篇:
分享到:更多 ()