コーディングヘルプ...アラートの代わりにインジケータをフィルタリングする方法を教えてください。 - ページ 8

 

U da man!

それで...私が正しく理解しているかどうか見てみましょう...

もし私が移動平均のバッククロスに基づいてポジションをクローズしたかったら、必要なコードはこれだけです....

if(currentlong>minorts) {CloseOrder(OP_SELL); // すべての売り注文を 閉じる}。

ここで、currentlong は 20ema であり、minorts は 150ema である。したがって、オープンポジションはショートであった、あるいはショートであったのだが、それが一巡し、現在 20ema が 150ema の上に移動している。

そして...

if (currentlong<minorts) {CloseOrder(OP_BUY); // すべての買い注文を閉じる}.

ここで、currentlongは20ema、minortsは150emaなので、オープンポジションはロングであった、あるいはロングが一巡し、現在20emaはロングトレードのクローズシグナルである150emaの下に移動している、ということになります。

そこで、次の2行を入れることができます。

if (currentlong<minorts) {CloseOrder(OP_BUY); // すべての買い注文を閉じる}。

if(currentlong>minorts) {CloseOrder(OP_SELL); // 全ての売り注文をクローズする}。

というように、エントリーコードの直後で、他のクローズやトレーリングストップの前に書くと、うまくいくでしょうか?

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

}

//+---------end of order entry-------------------------+

//+------close on moving average cross-----------------+

if(currentlong<minorts) {CloseOrder(OP_BUY);} // Close all buy orders}

if(currentlong>minorts) {CloseOrder(OP_SELL);} // Close all sell orders}

//+--------end of close on moving average cross--------+

//+-------------------------Trailing Stop Code------------------------------------+

for(cnt=0;cnt<total;cnt++) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {

if(OrderType()==OP_BUY){

コンパイラはこう言っています。

')' - wrong parameters count C:\Program FilesInterbank FX Trader 4-live mini</experts} (85, 43)

')' - wrong parameters count C:♪Program Files ♪Interbank FX Trader 4-live miniexperts ♪Whatever.mq4 (86, 44)

という行があるのですが、この行が気に入らないようです。なんかうまく伝わってない気がする。

 

いきなりですが、メタエディタの検索機能で面白いことがありました。

bool OrderCloseBy( int ticket, int opposite, color Color=CLR_NONE)

開いている注文を、別の反対側の開いている注文で閉じます。この関数が成功した場合、戻り値は真です。失敗した場合、戻り値はfalseです。詳細なエラー情報を得るには、GetLastError()を呼び出します

パラメータ

ticket - 注文チケットの一意の番号です。

opposite - 反対側の注文チケットの一意な番号です。

色 - チャート上の終値の矢印の色です。このパラメータがないか、またはCLR_NONEの値を持つ場合、チャート上に終値の矢印は描画されません。

サンプル

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)

{

OrderCloseBy(order_id,opposite_id)。

return(0);

}

というようなことをイメージしています。

if(currentlong<minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}[/PHP]

thing is this doesn't distinguish what kind of position I'm into first, long or short. So if I put the opposite side of this with it...like this...

[PHP] if(currentlong>minorts)

{

OrderCloseBy(order_id,opposite_id);

return(0);

}

もっとあるはずなのに......まだ言葉を話せない子供のように、自分の中で完結しているのに伝えられないもどかしさがあるんです。

 
elihayun:
私はこの1つを忘れてしまった
void CloseOrder(int ticket,double numLots,double close_price)

{

int CloseCnt, err;

// try to close 3 Times

CloseCnt = 0;

color clr = Violet;

if (OrderType() == OP_SELL)

clr = Orange;

while (CloseCnt < 3)

{

if (OrderClose(ticket,numLots,close_price,Slippage,clr))

{

CloseCnt = 3;

}

else

{

err=GetLastError();

Print(CloseCnt," Error closing order : (", err , ") " + ErrorDescription(err));

if (err > 0) CloseCnt++;

}

}

}

[/PHP]

and dont forget to add this line after #property link

[PHP]#property link "http://www.elihayun.com"

#include

これは何をするものなのでしょうか?私は、これが何をするのか、どのようにロングとショートのポジションを区別するのかを理解したいのです。私は学びたいのです。

 
Aaragorn:
U da man!

というわけで...私の理解が正しいかどうか確認してみましょう...。

つまり、次の2行を入れればいいわけです。

if (currentlong<minorts) {CloseOrder(OP_BUY); // すべての買い注文を閉じる}。

if(currentlong>minorts) {CloseOrder(OP_SELL); // すべての売り注文をクローズ}。

//+------移動平均線クロスでクローズ------------------------------------------

if(currentlong<minorts){CloseOrder(OP_BUY);}。全ての買い注文をクローズ} } //全ての買い注文をクローズ

if(currentlong>minorts) {CloseOrder(OP_SELL);}・・・全ての売り注文を決済。// 全ての売り注文を決済}。

if(OrderType()==OP_BUY){[/PHP]のようになります。

を実行すると、コンパイラはこう言います。

')' - wrong parameters count C:\Program FilesInterbank FX Trader 4-live mini Neitherexpertswhatever.mq4 (85, 43)

')' - wrong parameters count C:\Program Files' Interbank FX Trader 4-live miniexperts㏌WHATHERE.mq4 (86, 44)

というセリフが気に食わない。うまく伝わっていない気がする。

CloseOrder (that close only one order) ではなく、CloseOrders の最後に s をつけて呼び出さないといけません。

 
Aaragorn:
これは何をするものなのでしょうか。これを呼び出すには、他に何かダウンロードしなければならないのでしょうか。この関数が何をするのか、どのようにロングとショートを区別するのか理解したいのです。私は学びたいのです。

MQL4の一部で、ErrorDescription 関数が 含まれています。

 
elihayun:
MQL4の一部で、ErrorDescription 関数が含まれています。

OK移動平均の クロスバックに基づいてクローズするためのコードが必要です。

 

このコードで始めることができます。

もちろん、あなた自身のニーズに合わせて修正する必要があります。しかし、これが出発点となるはずです。このルーチンはSMA1ラインをトレーリングストップとして使用します。このアイデアをもとに、どんなことができるかを考えてみてください。

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

 

トレーリングストップのクローズは、私が最初にこれを理解することができれば、おそらく有用です....

このelihayunがくれたスニペットは、もし誰かがMAバッククロスに反応させる方法を見つけ出し、正しい方向に持っていくことができれば、うまくいくだろうと思います。op_buyとop_sellがどっちなのか、ロングポジションの決済に使うのはどっちなのか、ショートポジションの決済に使うのはどっちなのか、混乱してるんです。

//+------close on moving average cross-----------------+

void CloseOrders(int op)

{

int tik[30], t = 0;

for(int i =0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

if(OrderSymbol()==Symbol() && MagicNum==OrderMagicNumber() && OrderType() == op){

tik[t] = OrderTicket(); t++;

}

}

}

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}

}

}

//+--------end of close on moving average cross--------+[/PHP]

I think I see that at this point in the code it has selected the orders by ticket and it's figuring out to set the close price based on the bid or the ask. So I'm not sure which is which for long or short positions. If the ticket is a long position that means it was opened at the ask price right? so it should close on the bid price? so this snippet is saying use the bid price to close so I assume that's for a long position. THEN it asks the

if (op == OP_SELL) prc = Ask;

so I assume this is the first place in this code where we now know if we are looking at a long or a short position ticket.

Then it moves immediately to close. But if I can put my closing criteria in here BEFORE it does that???

here it is as I received it...

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}[/PHP]

so what I'm thinking is that this is the place in the code where I should insert the moving average criteria to trigger the close for long or short positions. Something like this...

[PHP]for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){

double prc = Bid;

if (op == OP_SELL) prc = Ask;

if (prc == Bid && currentlong minorts);

CloseOrder(tik, OrderLots(), prc);

}

Will this do it? I think it might if I understand correctly..

Please tell me coders if this is correct??

I think this connects the direction of the moving average cross to the type of position that the ticket is identifed as being.

if the bid is to close long positions so we know the ticket is for a long position then it can close long positions if the currentlongema < minortsEMA because it knows that the ticket is for a long position and the 20ema has moved below the 150ema.

If the ask is for closing short positions and the ticket is identified as a short position because it wants to close at the ask price and the currentlongEMA has moved above the minortsEMA because it knows the ticket is for a short position and the 20ema has moved above the 150ema.

if that is correct will adding this line to the code,

if (prc == Bid && currentlong minorts)

stop it from closing UNLESS each ticket fits this criteria?

...that for the long position the 20ema150ema?

if that is ok then the logic for deciding to close long or short based on the emacrossback is ok and it's worth fixing these errors

I get these errors from the compiler...

[PHP]Compiling 'whatever.mq4'...

'(' - function definition unexpected C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (85, 17)

'MagicNum' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 40)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (90, 87)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 13)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 17)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (91, 37)

't' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (96, 18)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (98, 22)

'op' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (100, 14)

'tik' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (102, 21)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 5)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 11)

'total' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'total' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 15)

'cnt' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'cnt' - variable not defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 21)

'{' - expression on global scope not allowed C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (108, 28)

'i' - variable is already defined C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (135, 11)

'}' - unbalanced parentheses C:\Program Files\Interbank FX Trader 4-live mini\experts\whatever.mq4 (165, 1)

16 error(s), 5 warning(s)

 

すべてのメンバーに提案したいのは、取引を終了する際に「カウントアップ」ルーチンを使用しないことです。例えば、次のようなものは使わないでください。

for (i = 0; i<t; i++)

{

if(OrderSelect(tik,SELECT_BY_TICKET)){ (オーダーセレクト(tik,SELECT_BY_TICKET))。

double prc = Bid;

if (op == OP_SELL) prc = Ask;

CloseOrder(tik, OrderLots(), prc);

}

複数の注文を使用している場合、最後の注文をクローズすることはありません。カウントダウン」ルーチンを使用してください。このイライラする「バグ」に最初に出くわしたときの、Metaquotesの開発者とのやり取りを紹介します。

http://www.metaquotes.net/forum/2018/

 
Maji:
このコードでうまくいくはずです...

もちろん、あなた自身のニーズに合わせて修正する必要があります。しかし、これが出発点となるはずです。このルーチンはSMA1のラインをトレーリングストップとして使用します。このアイデアをもとに、あなたが何を作ることができるか見てみましょう。

//these two lines within start()

SMA1 = iMA(NULL,TimePeriod,SlowPeriod,0,SlowMode,SlowPrice,1);

TrailingAlls(TrailStart, SMA1);

// trailing routine using the value of SMA1

void TrailingAlls(int start, double currvalue)

{

int profit;

double stoptrade;

double stopcal;

// if(stop==0) return;

int trade;

for(trade=OrdersTotal()-1;trade>=0;trade--)

{

if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

continue;

if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)

continue;

if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)

{

if(OrderType()==OP_BUY)

{

profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Bid-(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);

}//Long

if(OrderType()==OP_SELL)

{

profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);

if(profit<start)

continue;

stoptrade=OrderStopLoss();

// stopcal=Ask+(stop*Point);

stopcal=NormalizeDouble(currvalue, Digits);

if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))

OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);

}//Shrt

}

}//for

}

本当にありがとうございました。私はこれを分解して、私がそれを作ることができるものを見ることを楽しみにしています...

まずエマクロスバックを動作させたい理由は、基本的にそれが私のストップロスとデフォルトの出口戦略になるからです。

それが機能するようになったら、収益性を高めるためにこのようなものを追加するつもりです。しかし、ストップロスを 設定すると混乱しますし、巨大なストップロス・パラメーターも許容できませんので、まずは移動平均クロスバックのクロージングを機能させたいと考えています。もし機会があれば、私がこれまでクロスバッククローズで行ってきたことを検証していただけると幸いです。

理由: