コーディングの方法は? - ページ 287

 

...

この投稿を見てください :https://www.mql5.com/en/forum/174385/page12

同じような問題で、同じcountOpenedOnACurrentBar 関数を使って、クロスオーバーごとに1つの取引しかできないように制限することができます。

関数を使用して、クロスオーバーごとに1つの取引のみを開くように制限することができます。

dipu:
こんにちは、私は初心者です。私は簡単な戦略を持っています。私はEMAがクロスオーバーしたときにスキャルピングをするだけです。私はちょうどすべてのクロスオーバーで1つの取引を取る。私はすべてのEMAのクロスオーバーで1つだけの 貿易を取ることができるいくつかのコードが必要です。お願いします......
 

単純にEMAのクロスオーバーコードが必要なのか......。

MLADEN さん、ありがとうございました。

あなたの関数を チェックしました。それは良さそうに見えます。また、私はいくつかの助けを必要としています。EMAクロスオーバーでRSI(50) の値を追加する必要があるのですが、どうすればいいでしょうか?

ペアは? 英国ポンド/米ドル & 欧州ユーロ/米ドル

タイムフレーム: 15min,1h以上。

-------------------------------

BUY。EMA 5とEMA 12のクロスで上昇、RSIは50以上

売り:EMA5クロスEMA12が下降、RSIが50未満

(EMAのクロスオーバーで1回だけトレードします。)

ご返答お待ちしております。お願いします......。

 

いくつかの方法でそれを行うことができます。

一つの方法は、(EAで直接)このようなものです。

double macdc = iMA(NULL,0,EmaFast,0,MODE_SMA,EmaPrice,0)-iMA(NULL,0,EmaSlow,0,MODE_SMA,EmaPrice,0);

double macdp = iMA(NULL,0,EmaFast,0,MODE_SMA,EmaPrice,1)-iMA(NULL,0,EmaSlow,0,MODE_SMA,EmaPrice,1);

double rsi = iRSI(NULL,0,RsiPeriod,RsiPrice,0);

if (macdc*macdp<0) // change of sign, signal for a new order

{

if (macdc>0 && rsi>50) ... code for buy

if (macdc<0 && rsi<50) ... code for sell

}

[/PHP]

The good thing about it is that it is small (the code) and does not take any significant process time. The bad thing when using conditions like that in an EA is that you have to imagine (and test, test, test ...) what is it going to perform like. I prefer making a "binary" indicator with which the it is very easy to visually inspect if the condition has any logic in it and if it is going to be profitable or not and then call that indicator (using iCustom()) from the EA.

Here is how would the indicator with the above conditions look like in "binary" form :

必要な情報はすべて揃っている:灰色の線は「トレンド」です。緑と赤のラインは、エントリーやリエントリーのポイントとして使うことができます。視覚的に瞬時に「最適化」して、そのパラメータを EAで使う(「パラメータを変えて、実行して、結果をみて、同じことを繰り返す」よりも、視覚的にずっと早く「最適化」することができる。そして、それをEAから呼び出すのは割と簡単です。それは次のようになります。

[PHP] double trendc = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,0);

double trendp = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,1);

if (trendc!=trendp)

{

if (trendc== 1) ... 買いのシグナル

if (trendc==-1) ... 売りのシグナル

}

というわけで、全体として、私は常にEaからインジケータを利用することをお勧めします。EAに手を付けずに、インジケータのコードを変更・改良するだけでEAのロジックを変更することも可能で、その場合、EAは注文と資金管理のためのフレームワーク「だけ」になります(シグナルはインジケータから来ているので)これはEAを使う最も効率の良い方法だと私は思っています。インジケータも添付することで、EAで使用したい方法(直接または「インジケータによる」方法)を決定することができます。

PS: 上記の例では、テストは現在の(まだ開いている)バーで実施されています。もし、閉じたバーをテストしたい場合は、iCustom(),iMa(),iRSI()のコールで、0と1を1とtoに置き換えてください。

dipu:
MLADEN さん、ありがとうございました...。

私はちょうどあなたの関数をチェックします。それは良い見ています。私はまた、いくつかの助けを必要としています。EMAのクロスオーバーでRSI(50) の値を追加する必要があるのですが、どうしたらいいでしょうか?

ペアは? 英国ポンド/米ドル & 欧州ユーロ/米ドル

タイムフレーム: 15min,1h以上。

-------------------------------

BUY。EMA 5とEMA 12のクロスで上昇、RSIは50以上

売り:EMA5クロスEMA12が下降、RSIが50未満

(EMAのクロスオーバーごとに1回だけ取引する)。

返信を待っています。お願いします......。
ファイル:
 

月初めの残高?

Gidday 私はここに座って、画面上に表示するために、月の1日の開始残高を抽出する方法があるかどうかを把握しようとしています。

私がしようとしているのは、1日の残高と現在の残高の差の割合を取得することです。

私は、オーバーオール・パーセント・ディファレンスを持っています。

(残高 - 預金)/ 預金*100

毎月の差額を追加したいのですが

(残高-1日)/1日*100

何かヒントがあれば、または実際のコードを教えてください。

よろしくお願いします。

ベノ

 

MALADEN さん、いつもありがとうございます...

インジケータとアドバイスに感謝します。ただ、ご指示通りにやってみたのですがしかし、私はmq4に不慣れなため、失敗してしまいました.........................。

ここに私の..............................。

------------------------------------

-----------------------------------

#property indicator_separate_window(インジケータ分離ウィンドウ

#property indicator_buffers 3 (インジケーターバッファー3)

#property indicator_color1 ライムグリーン

#property indicator_color2 PaleVioletRed (ペールバイオレットレッド)

#property indicator_color3 DarkGray (ダークグレー)

#property indicator_width1 2 (プロパティインジケータ幅1)

#property indicator_width2 2 (プロパティ インジケータ幅2)

#property indicator_minimum -1.1

#property indicator_maximum +1.1 (最大値)

extern int EmaFast = 5;

extern int EmaSlow = 12;

extern int EmaPrice = PRICE_CLOSE;

extern int RsiPeriod = 14;

extern int RsiPrice = PRICE_CLOSE; extern int RsiPeriod = 14; extern int RsiPrice = PRICE_CLOSE;

double signup[];

double signdn[];

double trend[];

extern double TakeProfit=15.0;

extern double Lots=0.1;

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int init()

{

return(0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int start()

{

int count,counted_bars=IndicatorCounted();

if(counted_bars < 0) return(-1);

if(counted_bars>0) counted_bars--;

int limit = MathMin(Bars-counted_bars,Bars-1);

int cnt, ticket, total;

double trendc = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,0)。

double trendp = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,1); double trendp = iCustom(NULL,0, "ema + rsi binary",EmaPrice,RsiPeriod,RsiPrice,1,1);

if (trendc!=trendp)

total = OrdersTotal();

if(total < 1)

{

if (trendc== 1) //...買いのシグナル

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,「私のEA」,12345,0,Green);

if(チケット>0)

{

if(オーダーセレクト(チケット,SELECT_BY_TICKET,MODE_TRADES))Print("BUY order opened : ",OrderOpenPrice());

else Print("BUY注文の開始エラー :",GetLastError())。

return(0);

if (trendc==-1) //...売りのシグナル

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point, "My EA",12345,0,Red).このチケットは、売りのシグナルです。

if(ticket>0)

{

if(オーダーセレクト(チケット,SELECT_BY_TICKET,MODE_TRADES))Print("SELL order opened : ",OrderOpenPrice());

else Print("SELL注文の開始エラー :",GetLastError());

return(0);

}

return(0);

---------------------------------------

---------------------------------------

助けてくれ...

あなたが倒れたとき、私はあなたにもっと多くの側面があれば、私はあなたに謝った。しかし、私は本当に無力です....

私は応答を待っています。お願いします.......

 

...

以下のような感じで使ってみてください。

double balanceAtStartOfMonth(int forMonth)

{

double current = AccountBalance();

datetime startTime = iTime(NULL,PERIOD_MN1,forMonth);

//

//

//

//

//

for (int k=OrdersHistoryTotal()-1; k>=0; k--)

{

if (!OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)) break;

if (OrderCloseTime()<startTime) continue;

current -= (OrderProfit()+OrderSwap());

}

return(current);

}

forMonth は、残高を確認したい月を遡ったものです。そして、必要な月の初日の残高を計算します。関数では 入出金も考慮されます(OrderType() == 6)ので、問題なく動作するはずです。

Beno:
Gidday 私はここに座って、画面上に表示するために月の1日の開始残高を抽出する方法があるかどうかを考えていました。

私がやろうとしているのは、1日の残高と現在の残高の差のパーセンテージを得ることです。

私は、オーバーオール・パーセンテージの差を持っています。

(残高 - 預金) / 預金 *100

毎月の差額を追加したいのですが

(残高-1日)/1日*100

何かヒントがあれば、または実際のコードを教えてください。

乾杯

ベノ
 

...

インジケータから注文を管理することはできません。注文を管理できるのはスクリプトかEAだけです(あなたが探しているのはこのケースです)。あなたの投稿にあるコードはインジケータです。

私が投稿した例は、EAから使用するものです(私の理解では、あなたはすでに注文数を 制限したいEAをお持ちで、EMAとRSIの条件をテストしてエントリーを希望されているようです)。

dipu:
本当にありがとう、MALADEN...

インジケーターとアドバイスありがとうございました。ただただ、ご指示に従うのみです。しかし、私はmq4に不慣れなため、失敗してしまいました..........................。

ここに私の..............................。

------------------------------------

-----------------------------------

#property indicator_separate_window(インジケータ分離ウィンドウ

#property indicator_buffers 3 (インジケータバッファ3)

#property indicator_color1 ライムグリーン

#property indicator_color2 PaleVioletRed (ペールバイオレットレッド)

#property indicator_color3 DarkGray (ダークグレー)

#property indicator_width1 2 (プロパティインジケータ幅1)

#property indicator_width2 2 (プロパティ インジケータ幅2)

#property indicator_minimum -1.1

#property indicator_maximum +1.1 (最大値)

extern int EmaFast = 5;

extern int EmaSlow = 12;

extern int EmaPrice = PRICE_CLOSE;

extern int RsiPeriod = 14;

extern int RsiPrice = PRICE_CLOSE; extern int RsiPeriod = 14; extern int RsiPrice = PRICE_CLOSE;

double signup[];

double signdn[];

double trend[];

extern double TakeProfit=15.0;

extern double Lots=0.1;

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int init()

{

return(0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int start()

{

int count,counted_bars=IndicatorCounted();

if(counted_bars < 0) return(-1);

if(counted_bars>0) counted_bars--;

int limit = MathMin(Bars-counted_bars,Bars-1);

int cnt, ticket, total;

double trendc = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,0);

double trendp = iCustom(NULL,0, "ema + rsi binary",EmaFast,EmaSlow,EmaPrice,RsiPeriod,RsiPrice,2,1); double trendp = iCustom(NULL,0, "ema + rsi binary",EmaPrice,RsiPeriod,RsiPrice,1,1);

if (trendc!=trendp)

total = OrdersTotal();

if(total < 1)

{

if (trendc== 1) //...買いのシグナル

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,「私のEA」,12345,0,Green);

if(チケット>0)

{

if(オーダーセレクト(チケット,SELECT_BY_TICKET,MODE_TRADES))Print("BUY order opened : ",OrderOpenPrice());

else Print("BUY注文の開始エラー :",GetLastError())。

return(0);

if (trendc==-1) //...売りのシグナル

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point, "My EA",12345,0,Red).このチケットは、売りのシグナルです。

if(ticket>0)

{

if(オーダーセレクト(チケット,SELECT_BY_TICKET,MODE_TRADES))Print("SELL order opened : ",OrderOpenPrice());

else Print("SELL注文の開始エラー :",GetLastError());

return(0);

}

return(0);

---------------------------------------

---------------------------------------

助けてくれ...

あなたが倒れたとき、私はあなたにもっと多くの側面があれば、私はあなたに謝った。しかし、私は本当に無力です...

返信を待っています。お願いします......。
 

MLADEN さん、返信ありがとうございます。

すみません、そのコードを新しいEAに入れるように言われたような気がします。

ただ、お返事を理解し損ねてしまいました...。

そうですね。おっしゃる通りです...。

私はEAを持っていて、それを修正したかったのです。新しい条件を加えて......。

私の条件は

------------------------------------------------------

買います。EMA 5とEMA 12のクロスで上昇、RSIは50以上

売り: EMA 5とEMA 12のクロスで下降、RSIが50未満

出口:小さなテイクプロフィットで

(EMAのクロスオーバーで1回だけトレードする。)

ここで私のEAは.......

---------------------

---------------------

extern double Lots=0.1;

extern int TakeProfit=5;

extern int StopLoss=5;

extern int RSIPos=50;

extern int RSINeg=50;

extern int Slippage=2;

extern int abandon=101;

datetime bartime=0;

int bartick=0;

double p;

int cnt=0;

int OrdersPerSymbol=0;

double bullMA3=0;

double bearMA7=0;

double RSI=0;

bool RSIPOS=0;

bool RSINEG=0;

double TP;

double SL;

int init()

{

if (Symbol()=="AUDUSD") {TakeProfit= 60; StopLoss= 23; abandon=103;}.

if (Symbol()=="EURAUD") {TakeProfit= 95; StopLoss= 141; abandon=33;}.

if (Symbol()=="EURCHF") {TakeProfit=81、StopLoss=77、abandon=97;}。

if (Symbol()=="EURGBP") {TakeProfit=11、StopLoss=77、abandon=108;}。

if (Symbol()=="EURJPY") {TakeProfit=38、StopLoss=75; abandon=183;}.

if (Symbol()=="EURUSD") {TakeProfit=35、StopLoss=35; abandon=5;}.

if (Symbol()=="GBPCHF") {TakeProfit=79、StopLoss=98、abandon=113;}。

if (Symbol()=="GBPJPY") {TakeProfit=13、StopLoss=98; abandon=117;}.

if (Symbol()=="GBPUSD") {TakeProfit= 55; StopLoss= 100; abandon=69;}.

if (Symbol()=="USDCAD") {TakeProfit=66、StopLoss=76; abandon=106;}.

if (Symbol()=="USDCHF") {TakeProfit=117、StopLoss=78、abandon=111;}。

if (Symbol()=="USDJPY") {TakeProfit=53; StopLoss=74; abandon=110;}。

int deinit()

{

}

int start()

{

p=Point;

// エラーチェックと バーカウント

if(AccountFreeMargin()<(200*Lots)) {Print("-----NO MONEY"); return(0);}.

if(Bars<100) {Print("-----NO BARS "); return(0);}.

if(bartime!=Time[0]) {bartime=Time[0]; bartick++;}.

bullMA3=iMA(Symbol(),0,3,0,MODE_EMA,PRICE_CLOSE,1)とします。

bearMA7=iMA(Symbol(),0,7,0,MODE_EMA,PRICE_CLOSE,1);

RSI=iRSI(Symbol(),0,2,PRICE_CLOSE,2).if(RSI>RSIPos)。

if(RSI>RSIPos) {RSIPOS=true; RSINEG=false;}.

if(RSI<RSINeg) {RSIPOS=false; RSINEG=true;}.

OrdersPerSymbol=0;

for(cnt=OrdersTotal();cnt>=0;cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if( OrderSymbol()==Symbol() )

{

OrdersPerSymbol++;

}

}

if(OrdersPerSymbol==0)

{

if(bullMA3>(bearMA7+p) && RSINEG)

{

SL=Ask-(StopLoss*p);

TP=Ask+(TakeProfit*p);

OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,TP, "BUY "+CurTime(),0,0,White)。

bartick=0;

}

if(bullMA3<(bearMA7-p) && RSIPOS)

{

SL=Bid+(StopLoss*p)とします。

TP=Bid-(TakeProfit*p)とします。

OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP, "SELL "+CurTime(),0,0,赤);

bartick=0;

}

}

if(OrdersPerSymbol==1 && bartick==abandon)

{

if(OrderType()==OP_BUY)

{

OrderClose(OrderTicket(),Lots,Bid,Slippage,White)。

SL=Bid+(StopLoss*p);

TP=Bid-(TakeProfit*p);

オーダー送信(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP, "SELL "+CurTime(),0,0,Red);

bartick++;

}

if(OrderType()==OP_SELL)

{

OrderClose(OrderTicket(),Lots,Ask,Slippage,Red)。

SL=Ask-(StopLoss*p)。

TP=Ask+(TakeProfit*p)。

OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,「BUY」+CurTime(),0,0,White);

bartick++;

}

}

for(cnt=0;cnt<OrdersTotal();cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if( OrderSymbol()==Symbol() )

{

if(オーダータイプ()==OP_BUY))

{

if (オーダーマジック番号()==0)

{

if( ビッド-オーダーオープン価格() > 3*Point )

{

OrderClose(OrderTicket(),Lots,Bid,0,White)。

return(0);

}

}

}

if(OrderType()==OP_SELL)

{

if (オーダーマジック番号()==0)

{

if( 注文開始価格()-売値 > (3*Point) )

{

OrderClose(OrderTicket(),Lots,Ask,0,Red)。

return(0);

}

}

}

}

}

return(0);

}

-------------------

---------------------

どのように修正すればいいのでしょうか......? 返信を待っています。お願いします......。

 

ディップー

エントリーに関しては、これは問題なく動作します。

また、5桁のブローカーにも気を配り、エントリーはその通りに動作しています。rsiのデフォルトの期間は14(私はあなたが使用したいのか知りませんでした、コードでは期間2を使って いますが、それはおそらく短すぎます)です。Emaの期間はデフォルトで5と12です。また、現在クローズドバーをテストしています(バーが閉じるまで待ち、もし買いや売りのシグナルが存在すれば、注文を入力します)。

ファイル:
dipu.mq4  5 kb
 

MLADEN さん、ご返信ありがとうございます。

申し訳ありません。

BUYです。EMA5とEMA12のクロスで上昇、RSI[14]が50以上

売り:EMA5とEMA12のクロスで下降、RSI[14]が50未満

出口:小さなTP/Slで......(5pip)

(EMAのクロスオーバーで1回だけトレードする。)

試してみたので、結果をお知らせします。

また、修正されるかもしれませんし、されないかもしれません。

またよろしくお願いします....