Files
2024-01-25 04:05:58 +03:30

117 lines
4.8 KiB
Plaintext

void OnTick()
{
string signal = "";
double Sar = iSAR(_Symbol, _Period, 0.02, 0.2, 0);
if (Sar < Low[1] && Open[1] < Close[1])
{
signal = "buy";
}
if (Sar > High[1] && Open[1] > Close[1])
{
signal = "sell";
}
if (signal == "buy" && OrdersTotal() == 0)
OrderSend(_Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green);
if (signal == "sell" && OrdersTotal() == 0)
OrderSend(_Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red);
Comment("The Signal is :", signal);
if (Open[1] > Close[1] && OrdersTotal() > 0)
CloseBuyPosition();
if (Open[1] < Close[1] && OrdersTotal() > 0)
CloseSellPosition();
}
void OnTick()
{
/* string signal = "";
double Sar = iSAR( _Symbol, _Period, 0.02, 0.2, 0 );
if ( Sar < Low[1] && Open[1] < Close[1] ) signal = "buy";
if ( Sar > High[1] && Open[1] > Close[1] ) signal = "sell";
if ( signal == "buy" && OrdersTotal() == 0 ) OrderSend( _Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green );
if ( signal == "sell" && OrdersTotal() == 0 ) OrderSend( _Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red );
Comment( "The Signal is :", signal );
if ( Open[1] > Close[1] && OrdersTotal() > 0 ) CloseBuyPosition();
if ( Open[1] < Close[1] && OrdersTotal() > 0 ) CloseSellPosition();
*/
static int count_of_NOPs = 0;
if ( OrdersTotal() == 0 )
{ if ( Open[1] < Close[1]
&& Low[1] > iSAR( _Symbol, _Period, 0.02, 0.2, 0 )
) {
int rc = OrderSend( _Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green );
Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID TRY OrderSend( OP_BUY ) -> RESULTING RetCode ( tkt# ) == %d [yield GetLastError() == %d]",
rc,
GetLastError()
)
);
count_of_NOPs = 0; //------------------------------ .RESET
return; //------------------------------------------^ J.I.T./RET
}
if ( Open[1] > Close[1]
&& High[1] < iSAR( _Symbol, _Period, 0.02, 0.2, 0 )
) {
int rc = OrderSend( _Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red );
Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID TRY OrderSend( OP_SELL ) -> RESULTING RetCode ( tkt# ) == %d [yield GetLastError() == %d]",
rc,
GetLastError()
)
);
if ( )
count_of_NOPs = 0; //------------------------------ .RESET
return; //------------------------------------------^ J.I.T./RET
}
/* OTHERWISE: */
Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID NOP... (for %d time)",
++count_of_NOPs
)
);
// */
}
else
{ if ( Open[1] > Close[1] ) { Print( StringFormat( "HAVING %d ORDERS ACTIVE... WILL TRY CloseBuyPosition()...",
OrdersTotal()
)
);
CloseBuyPosition();
count_of_NOPs = 0; //---------- .RESET
return; //----------------------^ J.I.T./RET
}
if ( Open[1] < Close[1] ) { Print( StringFormat( "HAVING %d ORDERS ACTIVE... WILL TRY CloseSellPosition()...",
OrdersTotal()
)
);
CloseSellPosition();
count_of_NOPs = 0; //---------- .RESET
return; //----------------------^ J.I.T./RET
}
/* OTHERWISE: */
Print( StringFormat( "HAVING %d ORDERS ACTIVE... DID NOP... (for %d time)",
OrdersTotal(),
++count_of_NOPs
)
);
// */
}