どんな新人の質問でも、フォーラムを乱雑にしないように。プロフェッショナルは、通り過ぎないでください。Nowhere without you - 6. - ページ 539

 
tatianati:

ありがとうございました。うまくいって、子供のように喜んでいたのですが、アドバイザーが「new」と表示されなくなりました。どこで間違えたのか、教えてください。

はて、元々探していた場所ではなく、間違いを発見。自分では次の仕事に対応できない。

乖離幅(MAからの価格距離)の設定方法を教えてください。

extern string s10                = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>";
extern string s11                = ">>> Вход против МА";
extern int    iMA_Period         = 365;
extern int    iMA_OpenDistance   = 60;     // как задать диапазон? например 60-85 за его пределами не открывать ордеров

以下はエントリー部分です。

int GetSignal()
{
  int Signal = 0;

  double iMA_Signal = iMA(Symbol(), 0, iMA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0);
  
  int Ma_Bid_Diff = MathAbs(iMA_Signal - Bid)/vPoint;
  
  if(Ma_Bid_Diff > iMA_OpenDistance && Bid > iMA_Signal) Signal = -1;
  if(Ma_Bid_Diff > iMA_OpenDistance && Bid < iMA_Signal) Signal = 1;
  
  return(Signal);
}
 
tatianati:

はて、元々探していた場所ではなく、エラーを発見。次の仕事は自分一人ではこなせない。

乖離幅(MAからの価格の距離)を設定する方法を教えてください。

以下、エントリー部分


extern int    Min_iMA_OpenDistance   = 60;
extern int    Max_iMA_OpenDistance   = 85;

そして、それに応じて、条件

if(Ma_Bid_Diff > Min_iMA_OpenDistance && Ma_Bid_Diff < Max_iMA_OpenDistance && Bid > iMA_Signal)
 

アドバイザーの生データを正しく(1買い、-1売り)に変更する必要があります。

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

//| SimpleBars_rob.mq4
//| 著作権 © 2010, ENSED Team|電子書籍ストア「BookLive!
//| http://www.ensed.org |
//+------------------------------------------------------------------+
#property copyright"著作権 © 2010, ENSED Team"
#プロパティリンク "http://www.ensed.org"

extern int SL = 50; // ストップロス値(単位:ピップス)
TP = 150; // テイクプロフィット値(ポイント)
extern double Lots = 0.1; // 作業ロット(マイクロロット - 0.01、ミニロット - 0.1、ノーマルロット - 1.0)
extern string Order_Comment = "robot"; // 注文に適用されるコメント
extern int Slipage = 5; // 最大許容スリップレベル(単位:ポイント)
extern int int Magic_Number = 777; // ロボットのマジックオーダー数(「友好的」な取引を区別するため)
extern bool Play_Sound = false; // オープニング時のサウンドの再生:true - 許可、false - 禁止

//--------------------------------------------------------------------------------------------------------------------+
//+ SimpleBarsインジケータのタイムフレームとパラメータの設定
外部 int period = 6;
extern bool useClose = true;
extern int width = 3;
//+ SimpleBarsのタイムフレームとパラメータを調整します。
//--------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//+ トレーリングストップ
extern bool UseTrailing = true; // トレーリングストップのオン/オフ
extern int TrailingStop = 50; // 固定トレーリングストップ・サイズ(pips単位)。
extern int TrailingStep = 1; // トレーリングストップのステップ(ポイント数)
//+ トレーリングストップ
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| プログラムの初期化時に実行されます。
void init() {
if(GlobalVariableCheck("this_bar "+Symbol()+Period())))
GlobalVariableDel("this_bar "+Symbol()+Period())。
を返します。
}
//| プログラムの初期化時に実行される関数です。
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| プログラムの初期化時に実行される関数です。
void deinit() {
if(GlobalVariableCheck("this_bar "+Symbol()+Period())))
GlobalVariableDel("this_bar "+Symbol()+Period())。
を返します。
}
//| プログラムの非初期化時に実行される関数です。
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| 売買シグナルを検索する機能
int fsignals() {
double signal = iCustom(NULL, 0, "SimpleBars", period, 0, 1, 4, 0);
return(0); // 「買い」開始のシグナル
return(1); //オープンセル・シグナル
return(-1); // シグナルなし
} //end int fsignals()
//| 売買シグナルを検索する機能
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| 与えられたバーに対するロボットの作業を追跡する機能
bool this_bar() {
if(
(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
|| (GlobalVariableGet("this_bar "+Symbol()+Period()!=Time[0]))
){
GlobalVariableSet("this_bar "+Symbol()+Period(),Time[0]);
return(false)です。
} else {
return(true)です。
} //end if (.(!GlobalVariableCheck("this_bar "+Symbol()+Period()))
} //end bool this_bar()
//| 与えられたバーに対するロボットの動作の事実を追跡する機能
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| このタイプの注文を検索する機能です。
bool find_orders(int magic=-1, int type=-1, string symb="NULL") {.
/* 与えられたマジックナンバーを持つ、与えられた型のオーダーが、与えられたシンボルで少なくとも1つ見つかれば、trueを返す */。
for (int i=OrdersTotal()-1; i>=0; i--){
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if(((OrderType()==type) || (type==-1)))
&& ((OrderMagicNumber()==magic) || (magic==-1))
&& ((OrderSymbol()==Symbol() || (symb=="NONE")))){
//注文があれば return(true)してループを抜ける
return(true)です。
が壊れる。
} //end if((OrderType()==type) && (OrderMagicNumber()==magic) && (OrderSymbol()==Symbol()))
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)

return(false); //return false
} //end bool find_orders(int magic, int type)
//| 指定されたタイプの注文を検索する機能 |...
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| 注文のストップロス値を計算する機能です。
double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1) {。
//type=0→市場購入
//type=1→市場売上
if(symb=="NONE") symb=Symbol();
if(type==0) price=NormalizeDouble(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS))です。
if(type==1) price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS));
if(sl_value<=0) return(0);
if(rmode==1){。
if((type==0) || (type==2) || (type==4)) return(MarketInfo(symb,MODE_ASK)-sl_value*MarketInfo(symb,MODE_POINT)); //購入の場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_BID)+sl_value*MarketInfo(symb,MODE_POINT)); //販売用
}
if(rmode==2){。
if((type==0) || (type==2) || (type==4)) return(MarketInfo(symb,MODE_BID)-sl_value*MarketInfo(symb,MODE_POINT)); //買いの場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_ASK)+sl_value*MarketInfo(symb,MODE_POINT)); //売り出しの場合
}
} //end double sl(int sl_value, int type, double price=0.0, string symb="NONE", int rmode=1)
//| 注文のストップロス値を計算する関数です。
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//|注文の利食い値を計算する関数
double tp(int tp_value, int type, double price=0.0, string symb="NONE") {。
//type=0→成り行き買い
//type=1→市場売上
if(symb=="NONE") symb=Symbol();
if(type==0) price=Normalize Double(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS));
if(type==1) price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS));
if(tp_value<=0) return(0);
if((type==0) || (type==2) || (type==4)) return(price+tp_value*MarketInfo(symb,MODE_POINT)); //購入の場合
if((type==1) || (type==3) || (type==5)) return(MarketInfo(symb,MODE_BID)-tp_value*MarketInfo(symb,MODE_POINT)); //販売用
} //end double tp(int tp_value, int type, double price=0.0, string symb="NONE")
//| 注文のテイクプロフィット値を計算する関数です。
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| 注文を開始する機能
void open_positions(int signal, double lot, double price=0.0, string symb="NONE") { .
//シグナル=0→買いのオープンシグナル
//signal=1→売りのオープンシグナル
/* extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5;

int i = 0; //ループカウンタ用変数
int err = 0;

if(symb=="NONE") symb=Symbol();
if(signal==0)
price=Normalize Double(MarketInfo(symb,MODE_ASK),MarketInfo(symb,MODE_DIGITS)); //買いの開始価格
if(signal==1)
price=Normalize Double(MarketInfo(symb,MODE_BID),MarketInfo(symb,MODE_DIGITS)); //売りの開始価格

while(i<=Count_Of_Trade_Try) { [1]をクリックします。
注文を開くための // 関数(組み込み)。知覚の便宜のために、パラメータは別の行に配置されています。
int ticket = OrderSend(Symbol(), //symbol)
signal, //オーダータイプ
ロット、//ボリューム
価格, //オープン価格
Slipage, //リクオートの許容レベル
sl(SL,signal), // ストップロスの値
tp(TP,シグナル), //利益確定値取得
Order_Comment, //オーダーコメント
Magic_Number, //マジックナンバー
0, //有効期限(保留中の注文に使用)
CLR_NONE); //チャートに表示される矢印の色 (CLR_NONE - 矢印は描かれません)
if(ticket!=-1) //開封に成功した場合、グラフィックオブジェクトを描画してループを抜ける
が壊れる。
err=GetLastError()です。
if(err!=0) Print("エラー: "+Market_Err_To_Str(err));
i++;
Sleep(Pause_Of_Trade_Try*1000); //エラー発生時、再試行前に一時停止する。
} //end while(i<=count)
} //end void open_positions(int signal, double lot, double price=0.0, string symb="NONE")
//| 注文を開始する機能
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------+
//| エラーコードのデコード機能
string Market_Err_To_Str(int err) { (文字列)
/* この関数は、貿易業務のエラーコードのみを対象としています。
switch(err) {
case(0): return("エラーなし");
case(1): return("No error, but the result is unknown");
case(2): return("一般的なエラー");
case(3): return("Incorrect parameters");
case(4): return("取引サーバーはビジー状態です");
case(5): return("クライアント端末のバージョンが古い");
case(6): return("No connection to the trade server");
case(7): return("Not enough rights");
case(8): return("Too frequent requests");
case(9): return("Invalid operation disrupting server operation");
case(64): return("Account blocked");
case(65): return("Incorrect account number");
case(128): return("The deadline for the transaction is expired");
case(129): return("Incorrect price");
case(130): return("Incorrect stops");
case(131): return("Incorrect volume");
case(132): return("Market is closed");
case(133): return("取引禁止");
case(134): return("Not enough money to execute the transaction");
case(135): return("The price has changed");
case(136): return("価格なし");
case(137): return("The broker is busy");
case(138): return("新価格");
case(139): return("The order is blocked and is already being processed");
case(140): return("買いのみ許可");
case(141): return("Too many requests");
case(145): return("Modification is not allowed, because the order is too close to the market");
case(146): return("The trading subsystem is busy");
case(147): return("Use of expiry date is prohibited by broker");
case(148): return("未決済注文と保留注文の数がブローカーによって設定された上限に達しました。")
case(149): return("ヘッジが禁止されている場合に既存のポジションと反対のポジションを開こうとしました");
case(150): return("Attempting to close position on the symbol in contrary of the FIFO rule");

デフォルト:return("");
} //end switch(err)
} //end string Err_To_Str(int err)
//| エラーコードをデコードする関数
//+-------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------+
//| トランザクションの終了作業
//+----------------------------------------------------------------------------------------------------+
//| 注文番号(チケット)で注文を確定させる機能


bool close_by_ticket(int c_ticket, int slipage) {。
/*
取引番号(チケット)で決済する機能。
成行注文を決済する際に、最大許容スリッページのレベルを考慮する(スリッページ)
*/
/* extern */ int Count_Of_Trade_Try=5, Pause_Of_Trade_Try=5;

int i = 0; //ループカウンタ用変数
int err = 0;
bool ticket = false; //取引終了(不成立)時の変数
double price = 0.0; //取引終了時の価格(成行注文の場合)
if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES)){ //チケットの並び順を選択
if(OrderType()==OP_BUY) price = NormalizeDouble(Bid,Digits); //買いの場合の価格
if(OrderType()==OP_SELL) price = NormalizeDouble(Ask,Digits); //売りの場合の価格
for(i=0;i<=Count_Of_Trade_Try;i++) {
if(OrderType()<=1) //成行注文であれば決済、保留注文であれば削除
ticket=OrderClose(OrderTicket(),OrderLots(),price,slipage,CLR_NONE)とする。
さもなくば
ticket=OrderDelete(OrderTicket())とする。

if(ticket) { //クローズまたは削除が成功した場合 - trueを返してループを抜ける
return(true)です。
が壊れる。
} //終了 if(チケット)
err=GetLastError()です。
if(err!=0) Print("エラー: "+Market_Err_To_Str(err));
Sleep(Pause_Of_Trade_Try*1000); //エラー発生時、再試行前に一時停止する。
} //終了 for(i=0;i<=Count_Of_Trade_Try;i++)
} //終了 if(OrderSelect(c_ticket,SELECT_BY_TICKET,MODE_TRADES))

return(false); //return false
} //end bool close_by_ticket(int c_ticket)
//| 注文番号(チケット)で注文を確定させる機能
//+----------------------------------------------------------------------------------------------------+

bool cbm(int magic, int slipage, int type) {。
/*
魔法で閉じる(指定されたタイプの注文を指定されたMagicNumberですべて閉じる)
最大許容スリッページを考慮しています。
close_by_ticket関数を使用します。
*/
int n = 0;
while (find_orders(magic, type))
for (int i2=OrdersTotal()-1; i2>=0; i2--){
if (!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)) break;

if ((OrderType()==type) && (OrderMagicNumber()==magic)){
close_by_ticket(オーダーチケット(), slip;)
n++;
} //end if (((オーダータイプ()==OP_BUY) || (オーダータイプ()==OP_SELL)))&& (OrderMagicNumber()==magic))
} //end for (int i2=OrdersTotal()-1; i2>=0; i2--)

if(n>0)
return(true)です。

return(false)です。
} //終了 bool cbm(int magic, int slipage, int type)
//| 決算業務について
//+-------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| トレーリング・ストップ・ロス
void T_SL() {
if(!UseTrailing) return;
int i = 0;
for(i=0; i<OrdersTotal(); i++){
if(!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if(OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic_Number) continue;

if(OrderType()==OP_BUY){
if(NormalizeDouble(Bid-OrderOpenPrice(,Digits))>NormalizeDouble(TrailingStop*Point,Digits))。{
if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep-1)*Point,Digits))。
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //end if(NormalizeDouble(Bid-OrderOpenPrice(,Digits))>NormalizeDouble(TrailingStop*Point,Digits))とする。
} //end if(OrderType()==OP_BUY)の場合

if(OrderType()==OP_SELL)の場合{。
if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))。{
if(NormalizeDouble(OrderStopLoss(,Digits))>NormalizeDouble(Ask+(TrailingStop+TrailingStep-1)*ポイント,Digits))
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE)
} //end if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))とする。
} //end if(オーダータイプ()==OP_SELL)
} //終了 for(i=0; i<OrdersTotal(); i++)
} //end void T_SL()
//| トレーリング・ストップ・ロス
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//| メイン関数
void start() {

int sig = fsignals();

if(!find_orders(Magic_Number)){
if((sig!=-1)){
if(!this_bar()){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
}
} //end if((sig!=-1) && (!this_bar())
} else {
if(sig==0){とする。
if(cbm(Magic_Number, Slipage, 1)){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
} //終了 if(cbm(Magic_Number, Slipage, 1))
} //終了 if(sig==0)
if(sig==1) {
if(cbm(Magic_Number, Slipage, 0)){
open_positions(sig, Lots);
if(Play_Sound)
PlaySound("alert.wav")。
} //終了 if(cbm(Magic_Number, Slipage, 0))
} //end if(sig==1)
T_SL()です。
} //終了 if(!find_orders(Magic_Number))ほか
を返します。
}
//| メイン関数
//+-------------------------------------------------------------------------------------------------------------------+
 

愛好家の皆さん、こんにちは。ヘルプ-動作していません。 変数の初期化に戸惑ったと思います。頭が回転していますが、間違いは見つかりません。

EAは、ポジションを開く代わりに、Klose(0)の価格で矢印を描画し、閉じる代わりに、クロスを描画して、データ( fExpiration_func(Expiration)、fop_time、cl_time、fop_price、cl_price、ftype)を新しい行に出力する必要があります。

ここでは、確率論は例としてのみ取り上げられています。

 //+------------------------------------------------------------------+
//|                                                     binar_v1.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"


//--- input Time parameters
input uchar     hs = 9 ; 
input uchar     ms = 0 ; 
input uchar     he = 18 ; 
input uchar     me = 0 ;
//--- input Indicator parameters

//--- input Expiration parameters
input uchar     Expiration = 2 ; //время експирации в минутах


input bool      strategy_1  =   true ;


bool poz;                                   //открытая/закрытая позиция
datetime op_time;                         //время открытия
double op_price;                           //цена открытия
char type;                                 //тип открытой позиции -1 СЕЛЛ, 1- БАИ
//+=================================================================================+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- 
   
      
//---
   return ( INIT_SUCCEEDED );
  }
//+=================================================================================+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   
      
  }
//+=================================================================================+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
   //подщитаем арифметическое среднее OC за прошлую неделю
   //Пощет один раз в неделю    
     /* if(isNewBar("",PERIOD_W1)){      
         uchar iPr=iBarShift(NULL,PERIOD_M1,iTime(NULL,PERIOD_W1,1));
         uchar iPn=iBarShift(NULL,PERIOD_M1,iTime(NULL,PERIOD_W1,1))+10080;
         double avgM1=AvgOC(iPr,iPn,0);                                     // M1 OC цредняя за прошлую неделю               
      }*/
       if (!fisTradeTimeInt( 9 , 0 , 18 , 0 )) return ;                                 //Время торгов
       if (strategy_1== true )fStrategy1();
  }
//+=================================================================================+
//| Timer function                                                   |
//+------------------------------------------------------------------+

//+=================================================================================+
void fStrategy1
   (
   
   )
//--------------------   
{
   

   if (poz== true )                             //если есть открыта позиция
      fClose_Pos(op_time,op_price,type);       //закрываем
   if (poz== false ){                           //если нет открытой
      fOpen_buy(poz,op_time,op_price,type);   //покупка   
      fOpen_sell(poz,op_time,op_price,type);   //продажа
   }       
}
//+=================================================================================+
void fOpen_buy
   (
   bool & op,                                 //открытая/закрытая позиция
   datetime & out_op_time,                       //время открытия
   double & out_op_price,                         //цена открытия
   char & out_type                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//--------------------
{
   double stoch_M0_1 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 1 );
   double stoch_M0_2 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 2 );
   double stoch_M0_1s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 1 );
   double stoch_M0_2s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 2 );
   
   string arrowName;
   
   if (!op){      
       if (stoch_M0_1 < 20 && stoch_M0_2 < stoch_M0_2s && stoch_M0_1s < stoch_M0_1){
          out_type=- 1 ;
          op= true ;
          out_op_price= Close [ 0 ];
          out_op_time= Time [ 0 ];
          arrowName= "Buy" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );
          fDrawArrow(arrowName= "" ,out_op_price,out_op_time,Blue, 240 );               //стрелка открытой позиции
      }
          
   }     
}
//+=================================================================================+
void fOpen_sell
   (
   bool op,                                 //открытая/закрытая позиция
   datetime & out_op_time,                       //время открытия
   double & out_op_price,                         //цена открытия
   char & out_type                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//--------------------   
{      
   double stoch_M0_1 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 1 );
   double stoch_M0_2 = iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_MAIN , 2 );
   double stoch_M0_1s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 1 );
   double stoch_M0_2s= iStochastic ( NULL , 0 , 5 , 3 , 3 , MODE_SMA , 0 , MODE_SIGNAL , 2 );
   
   string arrowName;
   
   if (!op){      
       if (stoch_M0_1 > 80 && stoch_M0_2 > stoch_M0_2s && stoch_M0_1s > stoch_M0_1){
          out_type=- 1 ;
          op= true ;
          out_op_price= Close [ 0 ];
          out_op_time= Time [ 0 ];
          arrowName= "Sell" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );
          fDrawArrow(arrowName= "" ,out_op_price,out_op_time,Red, 240 );               //стрелка открытой позиции
      }
          
   }     
}
//+=================================================================================+
void fClose_Pos //jei yra atidaryta, uzdarom
   (
   datetime fop_time,                       //время открытия
   double fop_price,                       //цена открытия
   char ftype                               //тип открытой позиции -1 СЕЛЛ, 1- БАИ
   )
//-------------------   
{
   string arrowName= "Close" + TimeToStr ( TimeCurrent (), TIME_DATE | TIME_SECONDS );    
   double cl_price;
   string fileName= StringConcatenate ( "Strategy_1  " ,Expiration, " " , Period (), ".csv" );
   
   if (Expiration<= 5 ){                     //
       datetime cl_time= Expiration* 60 +op_time;                                         //время закрытия
       if ( TimeCurrent ()>=cl_time){
         
         cl_price= Close [ 0 ];               //цена закрытия         
         fDrawArrow(arrowName,cl_price,cl_time,Yellow, 251 );                             //наносим крестик на график
         fSaveToFile(fileName,Expiration, fop_time, cl_time, fop_price, cl_price, ftype);   //в новую строку сохроняем в файле
      }   
   }
   else {
      cl_time= fExpiration_func(Expiration)* 60 +op_time;                                 //время закрытия
      
       if ( TimeMinute ( TimeCurrent ())>= TimeMinute (cl_time)){
         
         cl_price= Close [ 0 ];      
         fDrawArrow(arrowName,cl_price,cl_time,Yellow, 251 );                             //наносим крестик на график
         fSaveToFile(fileName,fExpiration_func(Expiration), fop_time, cl_time, fop_price, cl_price, ftype); //в новую строку сохроняем в файле
     }
   }   
}
//+=================================================================================+
bool fisNewBar 
   (
   string f_sy,   
   int f_tf
   )
{
     int iIndex = - 1 ;
//----
     switch (f_tf)
    {
         case 1     : iIndex = 0 ; break ;
         case 5     : iIndex = 1 ; break ;
         case 15    : iIndex = 2 ; break ;
         case 30    : iIndex = 3 ; break ;
         case 60    : iIndex = 4 ; break ;
         case 240   : iIndex = 5 ; break ;
         case 1440 : iIndex = 6 ; break ;
         case 10080 : iIndex = 7 ; break ;
         default    : iIndex =- 1 ; break ;
    }
    
     static int LastBar[ 8 ]= { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; 
     datetime curbar = iTime (f_sy, f_tf, 0 );
     if (LastBar[iIndex] != curbar)
    {
        LastBar[iIndex] = curbar;
         return ( true );
    }
     else
    { return ( false );
 }
 }
//+=================================================================================+
int fExpiration_func
   (
   uchar e
   )
//--------------------   
{  
   uchar ex= 0 ;
   uchar mod= 0 ;
   if (e< 6 ) 
      ex=e; //return(e);
   else {
      mod= fmod (e, 5 );
       if (mod== 4 ) 
         ex=e+mod; //return(e+mod);
       else
         if (mod < 4 ) 
            ex=e-mod; //return(e-mod);
    }     
   return (ex); //grazina laiko tarpa minutemis
}
//+=================================================================================+
bool fisTradeTimeInt     //время торгов
   (
   uchar hstart= 0 , 
   uchar mstart= 0 , 
   uchar hend= 0 , 
   uchar mend= 0
   ) 
//--------------------   
{
   datetime db, de;           
   uchar       hc;              

  db= StrToTime ( TimeToStr ( TimeCurrent (), TIME_DATE )+ " " +hstart+ ":" +mstart);
  de= StrToTime ( TimeToStr ( TimeCurrent (), TIME_DATE )+ " " +hend+ ":" +mend);
  hc= TimeHour ( TimeCurrent ());
   if (db>=de) {
     if (hc>=hend) de+= 24 * 60 * 60 ; 
     else db-= 24 * 60 * 60 ;
  }
   if ( TimeCurrent ()>=db && TimeCurrent ()<=de) return ( True );
   else return ( False );
}
//+=================================================================================+
void fDrawArrow //наносим стрелки на график
   (
   string arrowName= "" ,
   double dwPrice= 0 ,
   datetime dwTime= 0 ,
   color dwColor=Silver,
   uchar dwArrowIndex= 0
   )
//--------------------   
{
   ObjectCreate       ( 0 ,arrowName, OBJ_ARROW , 0 , 0 , 0 , 0 , 0 );                 // создадим стрелку
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_ARROWCODE ,dwArrowIndex);       // установим код стрелки
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_COLOR ,dwTime);                 // зададим время
   ObjectSetInteger   ( 0 ,arrowName, OBJPROP_COLOR ,dwColor);               // зададим Цвет
   ObjectSetDouble    ( 0 ,arrowName, OBJPROP_PRICE ,dwPrice);               // зададим цену
   ChartRedraw ( 0 );
}
//+=================================================================================+
//Aritmetinis vidurkis

double fAvgOC
   (
   uchar count_start,       //nuo kurio baro pradesim skaiciuoti
   uchar end_count,         //iki kurio baro skaiciuosime
   uchar j= 0                //keli barai is eiles
   )
//--------------------   
{
   static double sum= 0 ;
   if (sum== 0 ){
       int n= 0 ;
       for ( int i=end_count; i<count_start; i++){
         double h= iClose ( NULL , PERIOD_M1 ,i);  
         double l= iOpen ( NULL , PERIOD_M1 ,i+j); 
         sum+= fabs (h-l);                   //padidinam avg 
         n++;                             //kie kartu buvo didintas avg
      }
       double avg=sum/n;                           //Surandam Mean aritmetini vidurki                 
   }   
   return (avg);                           //grazina kainu skirtumo vidurki
}
//+=================================================================================+
void fSaveToFile
   (
   string fileName,
   char expirration,       //realus ekspiracijos laikas minutemis
   datetime fop_time,
   datetime fcl_time,
   double fop_price,
   double fcl_price,
   uchar ftype
   )
//--------------------   
{
   //--- правильный способ работы в "файловой песочнице"
   ResetLastError ();
  
   int filehandle= FileOpen (fileName, FILE_WRITE | FILE_CSV );
   if (filehandle!= INVALID_HANDLE )
     {
      FileWrite(filehandle,
               expirration, //real expiration time
               fop_time, //TimeToStr(op_time,TIME_DATE|TIME_SECONDS),
               fcl_time, //TimeToStr(cl_time,TIME_DATE|TIME_SECONDS),
               op_price,
               fcl_price,
               type);
       FileClose (filehandle);
       Print ( "FileOpen OK" );
     }
   else Print ( "Операция FileOpen неудачна, ошибка " ,GetLastError());
}
//+=================================================================================+
/*int gUrdala_News()
{
   HideTestIndicators(true);
   int nResult = iCustom(NULL, PERIOD_M1, "Urdala_News", MinDo, MinPosle, ChasPoyasServera, 0, 0);
   HideTestIndicators(false);
   return(nResult);
}*/
//+=================================================================================+
/*datetime SecondsAfter    //grazinamas laiko tarpas po timeOp
   (
   datetime timeOp,      //laiko atskaitos pradzia
   datetime t
   ) 
{
     
   if (t<timeOp) t=timeOp;          
   return(TimeCurrent()-t);
}*/
//+=================================================================================+
//---------------------------------------------------
   /* void click
   (
   int x, 
   int y
   ) 
   {    
      SetCursorPos(x,y); // см. тут _http://www.vsokovikov.narod.ru/New_MSDN_API/Cursor/fn_setcursorpos.htm 
      mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); 
      mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); 
   }*/
//+=================================================================================+
//---------------------------------------------------
   /*void key
   (
   uchar kodas
   )
   {  
      keybd_event(kodas,0,0,0);      
      keybd_event(kodas,0,KEYEVENTF_KEYUP,0); 
   } */   
 

そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー

void OnTick()
  {
//---
   
   xy(10,20,100,100);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy,int & x,int & y){
   x=xx*xxx;
   y=yy+yyy;
}
 
gince:

そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー


void OnTick()
  {
//---
   int x,y;
   xy(10,20,100,100,x,y);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy, int &x,int &y){
   x=xx*xxx;
   y=yy+yyy;
}
 
gince:

そこで問題は、2つの値をどのように返すかである。試してみましたが、エラー


変数の使用は試されましたか?もしかしたら、それが役に立つかもしれません。

void OnTick()
  {
//---
   int x=100.0, y=100.0;
   xy(10,20,100, 100, x,y);
   Print("x=",x,"y=",y);
  }
//+------------------------------------------------------------------+
void xy(int xx,int xxx, int yy,int yyy,int & x,int & y){
   x=xx*xxx;
   y=yy+yyy;
}
 

もしよろしければ、お手伝いください

Expert Advisorにインジケータを使ったトレードを教えるために

BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910

UP= iCustom(Symbol(),NULL, "Now",BQuant,0,0);

DOW= iCustom(Symbol(),NULL, "Now",BQuant,1,0);


if(DOW){OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red);}{OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red)


if(UP ){OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue);}{OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue)


コメント

(

"ⅳプロフィット"。", UP,

"ⅳプロフィット"。", DOW

);

コメントで値を読もうとしたが、常に静的な値になっている。

 
Vinin:


変数の使用は試されましたか?役に立つかもしれません。


ありがとうございます、うまくいきました。

 
sannin:

もしよろしければ、お手伝いください

Expert Advisorにインジケータを使ったトレードを教えるために

BS_Living Now ver #1.mq4 https://www.mql5.com/ru/code/11014#50910


UP= iCustom(Symbol(),NULL,"Now",BQuant,0,2);//

DOW= iCustom(Symbol(),NULL,"Now",BQuant,1,2);


if(DOW != 0){OrderSend(Symbol(), OP_SELL, Lot, Bid, Slip, 0, 0, "Forex-Robots.ru SELL", Magic, 0,Red);}



if(UP != 0){OrderSend(Symbol(), OP_BUY, Lot, Ask, Slip, 0, 0, "Forex-Robots.ru BUY", Magic, 0,Blue);}
あまり詳しくはないのですが、こんな感じでしょうか。