以下にコードを載せてあります。
1分足確定時にRSIのゴールデンクロス、デッドクロスでエントリーして、1分後に決済するコードを書いているつもりですがうまくいきません。どのように書き直したらよいのでしょうか。ご教授お願い致します。
MQL4 //+------------------------------------------------------------------+ //| BO.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern bool UseEntryPer1Bar=true; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int gPrvBars=0; int cnt,CurrentPosition; double old_fast_rsi,old_slow_rsi,now_fast_rsi,now_slow_rsi; datetime OrderTime,CloseTime; int Ticket; int order_select; bool order_close; CurrentPosition=-1; int currentBars = Bars; // ----------------------------------------------------------------- // 仕掛けフィルター(1本の足で1回だけ仕掛ける) // ----------------------------------------------------------------- for(cnt=0;cnt<OrdersTotal();cnt++) { order_select = OrderSelect(cnt,SELECT_BY_POS); if(OrderSymbol() == Symbol()) { CurrentPosition=cnt; } } old_fast_rsi=iRSI(NULL,0,10,PRICE_CLOSE,2); old_slow_rsi=iRSI(NULL,0,75,PRICE_CLOSE,2); now_fast_rsi=iRSI(NULL,0,10,PRICE_CLOSE,1); now_slow_rsi=iRSI(NULL,0,75,PRICE_CLOSE,1); if(UseEntryPer1Bar){ // 新しい足を生成した時ではない場合は、仕掛けない if(currentBars == gPrvBars){ gPrvBars = currentBars; return; } } if(old_fast_rsi<old_slow_rsi&&now_fast_rsi>=now_slow_rsi) { Ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,30,0,0,"Buy",0,0,clrAliceBlue); if(OrderOpenTime()-TimeCurrent()==60) { order_select=OrderSelect(CurrentPosition,SELECT_BY_POS); if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { order_close=OrderClose(OrderTicket(),OrderLots(),Bid,30,Green); } } } } if(old_fast_rsi>old_slow_rsi && now_fast_rsi <= now_slow_rsi) { Ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,30,0,0,"SELL",0,0,clrRed); OrderTime=TimeCurrent(); if(OrderOpenTime()-TimeCurrent()==60) { order_select=OrderSelect(CurrentPosition,SELECT_BY_POS); if(OrderSymbol()==Symbol()) { if(OrderType()==OP_SELL) { order_close=OrderClose(OrderTicket(),OrderLots(),Ask,30,Green); } } } } //--- } //+------------------------------------------------------------------+ ```
あなたの回答
tips
プレビュー