随机的 - 页 6

 
king1898:

在这幅图中,两个箭头应该产生两个信号,但我的EA却不能发送,为什么?

因为我们没有看到你所有的代码,所以很难说。你可以打印你的缓冲区数值来检查和 比较。
 
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//-------------------------------------------------------------------


//-------------------------------------------------------------------
#include <Trade\Trade.mqh>
//--- input parameters
input int      StopLoss=-100;      // Stop Loss$
//input int      TakeProfit=100;   // Take Profit
//input int      KD_Period=9;     // KD Period
input int      K_Period=9;     // K Period
input int      D_Period=3;     // D Period
//input int      MA_Period=8;      // Moving Average Period
input int      EA_Magic=12345;   // EA Magic Number
//input double   Adx_Min=22.0;     // Minimum ADX Value
//---
//---input double Lot=0.01;   // Lots to Trade
input double MaxPosition=3.00;  //Max position
input double P1=0.12;    //P1 position1
input double P2=0.32;
input double P3=0.77;
input double P4=1.92;
input double P5=2.85;
input double P6=3.57;
//
input double PF1=10;     //PF1 profit1
input double PF2=50;
input double PF3=100;
input double PF4=500;
input double PF5=800;
input double PF6=1500;

//

//--- Other parameters
int KDHandle; // handle for our stochastic indicator
//int maHandle;  // handle for our Moving Average indicator
double K[],D[]; // Dynamic arrays to hold the values of K,D values for each bars
//double maVal[]; // Dynamic array to hold the values of Moving Average for each bars
double p_close; // Variable to store the close value of a bar
int STP, TKP;   // To be used for Stop Loss & Take Profit values
double TTL_profit;  //to be used for Total profit
//double hisBuyLot=0.05;
//double hisSellLot=0.05;
double TTLBuy_position;
double TTLSell_position;
int Buytimes;  //to be use for buy times
int Selltimes; // to be used for sell times
bool special_close_p=false;
double special_profit=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Get handle for KD indicator
   KDHandle=iStochastic(NULL,0,K_Period,D_Period,3,MODE_SMA,STO_LOWHIGH);
//--- Get the handle for Moving Average indicator
//   maHandle=iMA(_Symbol,_Period,MA_Period,0,MODE_EMA,PRICE_CLOSE);
//--- What if handle returns Invalid Handle
   if(KDHandle<0)
     {
      Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
      return(-1);
     }

//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
   //STP = StopLoss;
   //TKP = TakeProfit;
   //if(_Digits==5 || _Digits==3)
   //  {
   //   STP = STP*10;
   //   TKP = TKP*10;
   //  }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- Release our indicator handles
   IndicatorRelease(KDHandle);
//   IndicatorRelease(maHandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- Do we have enough bars to work with
   if(Bars(_Symbol,_Period)<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }  

// We will use the static Old_Time variable to serve the bar time.
// At each OnTick execution we will check the current bar time with the saved one.
// If the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

// copying the last bar time to the element New_Time[0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true;   // if it isn't a first call, the new bar has appeared
         if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
      Alert("Error in copying historical times data, error =",GetLastError());
      ResetLastError();
      return;
     }

//--- EA should only check for new trade if we have a new bar
   if(IsNewBar==false)
     {
      return;
     }

//--- Do we have enough bars to work with
   int Mybars=Bars(_Symbol,_Period);
   if(Mybars<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }

//--- Define some MQL5 Structures we will use for our trade
   MqlTick latest_price;      // To be used for getting recent/latest price quotes
   MqlTradeRequest mrequest;  // To be used for sending our trade requests
   MqlTradeResult mresult;    // To be used to get our trade results
   MqlRates mrate[];          // To be used to store the prices, volumes and spread of each bar
   ZeroMemory(mrequest);      // Initialization of mrequest structure
/*
     Let's make sure our arrays values for the Rates, KD Values 
     is store serially similar to the timeseries array
*/
// the rates arrays
   ArraySetAsSeries(mrate,true);
// the KD Kvalues array
   ArraySetAsSeries(K,true);
// the KD Dvalues array
   ArraySetAsSeries(D,true);
// the ADX values arrays
//   ArraySetAsSeries(adxVal,true);
// the MA-8 values arrays
//   ArraySetAsSeries(maVal,true);


//--- Get the last price quote using the MQL5 MqlTick Structure
   if(!SymbolInfoTick(_Symbol,latest_price))
     {
      Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
      return;
     }

//--- Get the details of the latest 3 bars,default period,
   if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
     {
      Alert("Error copying rates/history data - error:",GetLastError(),"!!");
      ResetLastError();
      return;
     }

//--- Copy the new values of our indicators to buffers (arrays) using the handle
   if(CopyBuffer(KDHandle,0,0,2,K)<0 || CopyBuffer(KDHandle,1,0,2,D)<0)
     {
      Alert("Error copying Stochastic KD indicator Buffers - error:",GetLastError(),"!!");
      ResetLastError();
      return;
     }
//     
   double Buy_order=0.02;  //Buy order 
   double Sell_order=0.02;
   
//--- we have no errors, so continue
//--- Do we have positions opened already?
   bool Buy_opened=false;  // variable to hold the result of Buy opened position
   bool Sell_opened=false; // variables to hold the result of Sell opened position

   if(PositionSelect(_Symbol)==true) // we have an opened position
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         Buy_opened=true;  //It is a Buy
         //Print("here - " , PositionsTotal());
         Print("1-Buy_opened - Total Buy position is ", PositionGetDouble(POSITION_VOLUME));
         TTLBuy_position=PositionGetDouble(POSITION_VOLUME);
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
         Sell_opened=true; // It is a Sell
         //Print("here - " , PositionsTotal());
         Print("1-Sell_opened - Total Sell position is ", PositionGetDouble(POSITION_VOLUME));
         TTLSell_position=PositionGetDouble(POSITION_VOLUME);
        }
     }

// Copy the bar close price for the previous bar prior to the current bar, that is Bar 1
   p_close=mrate[1].close;  // bar 1 close price
   


/*
    1. Check for a long/Buy Setup : k/d cross 20 
*/
//--- Declare bool type variables to hold our Buy Conditions
   bool Buy_Condition_1 = (K[0]>=D[0] && K[1]<=D[1]); // k>=D and K1<=D1
   bool Buy_Condition_2 = (K[1]<=20 && D[0]<=20); // k1<=20 and d<=20

   
//--- Check buy condition   
   if(Buy_Condition_1 && Buy_Condition_2)
     {
         Print("Buy-1:When buy OK, K0 is:",K[0]," D0 is:",D[0]," K1 is:",K[1]," D1 is:",D[1]);
 

谢谢angevoyageur!

我打印出来的这些变量缓存和我之前说的是一样的,当时应该发送信号,但K/D值是错误的,但看程序是正确的,这是否是MQL5的一个错误呢?

 
king1898:

谢谢angevoyageur!

我打印出来的这些变量缓存和我之前说的是一样的,在应该发送信号的时候,但K/D值是错误的,但看程序是正确的,这是否是MQL5的一个错误?

这个问题是一个基础问题,在下面的部分检查酒吧时间是否有问题?

//--- Do we have enough bars to work with
   if(Bars(_Symbol,_Period)<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }  

// We will use the static Old_Time variable to serve the bar time.
// At each OnTick execution we will check the current bar time with the saved one.
// If the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

// copying the last bar time to the element New_Time[0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true;   // if it isn't a first call, the new bar has appeared
         if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
      Alert("Error in copying historical times data, error =",GetLastError());
      ResetLastError();
      return;
     }

//--- EA should only check for new trade if we have a new bar
   if(IsNewBar==false)
     {
      return;
     }

//--- Do we have enough bars to work with
   int Mybars=Bars(_Symbol,_Period);
   if(Mybars<60) // if total bars is less than 60 bars
     {
      Alert("We have less than 60 bars, EA will now exit!!");
      return;
     }
 
king1898:

这是一个基础问题,在检查酒吧时间方面是否有问题?

谁能帮助我?谢谢。
 
king1898:
谁能帮助我?谢谢。

谢谢Angevoyageur

我检查了你的另一个回复,也许你是对的:是的,封闭的蜡烛信号更好,因为当前的信号可能是假信号。虽然也有一些交易者在开盘的蜡烛上交易,可能有一些过滤器。

我将尝试进行测试。

 

关于交易、自动交易系统和测试交易策略的论坛

指标。随机震荡指标

newdigital, 2013.10.09 07:23

利用随机指标准确定位外汇趋势交易的入口

  • 上升趋势是由较高的高点和较高的低点组成的。交易者可以利用随机震荡指标在趋势中的那些低位支撑点找到极好的风险与回报的入口。
  • 下降趋势是由较低的高点和较低的低点组成的。外汇交易员可以利用随机指标在这些阻力高点找到极好的风险回报入口。
  • Stochastics可以用来提醒外汇交易者在趋势交易中收紧止损,减少头寸大小,或者一旦获利就立即止损。

到目前为止,顺着每日主要趋势方向交易的交易者比逆趋势交易的交易者有更高的成功率。外汇市场最大的吸引力之一,它的特点是长趋势,如果交易者准确地掌握了进场时间,并使用保护性止损来限制风险,就有可能赚取数百点。


但是,交易员如何才能找到有风险的地方进入以获得最大收益?

在许多交易书籍中都可以看到 "趋势是你的朋友,直到它结束 "的咒语,但似乎许多外汇交易者并没有将趋势作为他们的朋友,在某些情况下,趋势已经成为敌人。许多交易者不是在接受那些正确进入趋势的交易者所获得的点数,而是在 "给予 "交易的一端,在对抗趋势的同时损失点数。

就像人们求助于在线约会服务来满足他们的理想对象一样,外汇交易者可以求助于随机指标,作为使趋势再次成为他们的朋友的一种方式。


在日线图的上升趋势中,随机指标%K和%D线移动到水平 "20 "参考线以下,并回到20线以上,表明获利回吐修正即将结束。随机指数向上交叉也告诉我们,买家开始再次进入市场。此外,这表明有良好的支持。

如何利用随机指标交易趋势

在试图利用趋势进行交易时,耐心是游戏的名称。过早进入趋势可能会使交易者面临巨大的跌幅。太晚进入则会减少波段完成前的利润额。

使用随机指标找到 "黄金分割点",即不要太早也不要太晚进入。一旦发现强劲的上升趋势,等待设置为15、5、5的随机指标进入20水平参考线以下的超卖区域。接下来,等待%K线和%D线重新移动到20线以上。进入多头,止损放在最后一个低点以下几个点。设置一个至少是止损规模两倍的限制。


一旦进入上升趋势位置,交易者将试图尽可能多地榨取利润。一旦随机指标进入超买区域,交易者通常会在他们的未平仓头寸上获利或追踪止损。值得注意的是,即使随机指标处于超买区域,外汇货币对也可以继续创造新的高点。

因此,下次当你看到一个趋势,而你不知道如何让它成为你的 "朋友 "时,让随机指标来介绍你吧一旦这些波动被随机指标所强调,止损位置也会变得更容易。 上升趋势中的随机指标交叉点可以帮助你准确定位你的入口,加入主要趋势。


 

关于交易、自动交易系统和测试交易策略的论坛

有趣的事情

Sergey Golubev, 2016.03.28 14:13

对于新手来说,这是一个非常好的EA--对于那些正在学习随机指标如何工作的交易者来说。该EA在随机指标的超买/超卖水平上进行交易,并在该EA中编入了以下参数。

  • 本EA中编码的随机指标的参数:5/3/3
  • 将在EA中编码的超买/超卖水平:80/20
ea_Stochastic_system - MetaTrader 4的专家
  • "顾问分析随机指标的读数,买入的信号是主指标和信号线在超卖区的交集,销售的信号是主指标和信号线在超买区的 交集。"

编码员为这个EA提出了设定文件,所以我们可以根据这个设定文件/参数在欧元兑美元M15时间框架上使用这个EA。

我对EA进行了回测,只是想看看它是如何工作的--请看回测结果和一些图表,以及关于超买/超卖水平的想法。






 

你好

我最近遇到了一个关于随机指数 的问题。

我用我自己写的EA进行交易。卖出交易的条件之一是Stoch Main at bar 1 < Stoch Signal Bar 1。

从附件中的GBPUSD文件,我们可以看到在10:00,Stoch Main Bar 1 > Stoch Signal Bar 1,但卖出交易是开放的。

我在Stochstic中使用的公式是

double StochMain1T30 = iStochastic(NULL,30,10,10,3,MODE_EMA,0,MODE_MAIN,1); // T30 MODE_MAIN

double StochSignal1T30 = iStochastic(NULL,30,10,10,3,MODE_EMA,0,MODE_SIGNAL,1); // T30 MODE_SIGNAL

我怀疑的一种可能性是,基于上述的StochMain1T30 < StochSignal1T30,但这不是我们在图表上看到的。

能否帮我解释一下上述情况?

我已经打电话给Oanda经纪商,他们告诉我,这个头寸不是他们开的,是EA开的。

谢谢你。

附加的文件:
 

关于交易、自动交易系统和测试交易策略的论坛

2014年4月读到的有趣的东西

Sergey Golubev, 2014.04.14 20:48

随机过程理论:在金融数学和风险理论中的应用



本书是一本习题集,涵盖了现代随机过程理论及其应用的所有主要课题,包括金融、精算数学、排队理论和风险理论。

本书的目的是为读者提供必要的理论和实践材料,以加深对随机过程理论及其相关领域的主要课题的理解。

本书根据不同的主题分为若干章节。每一章都包含问题、提示、解决方案,以及自成一体的理论部分,给出了解决问题的所有必要材料。还给出了文献的参考资料。

练习有不同的复杂程度,从简单的,对学习基本概念和技术的学生有用的,到非常高级的,揭示了一些重要的理论事实和结构的。

本书是随机过程理论及其应用中最大的问题集之一。本书中的问题对本科生和研究生,以及随机过程理论的专家都很有用。


原因: