MA_cross_Method_PriceMode
| extern int | MA1_Period=9; | comment | int | New_bar; | *(fact of creating new bar) | comment | ||
| extern int | MA2_Period=13; | int | Time_0; | |||||
| extern int | MA1_Method=0; | int | PosOpen; | *(direction of crossing) | ||||
| extern int | MA1_Method=3; | int | PosClose; | *(direction of crossing) | ||||
| extern int | MA1_Price=0; | int | Total; | *(orders amount) | ||||
| extern int | MA2_Price=4; | double | MA1_0; | *(current value) | ||||
| extern int | MA1_Shift=0; | double | MA1_1; | *(previous value) | ||||
| extern int | MA2_Shift=0; | double | MA2_0; | *(current value) | ||||
| extern double | Lot = 0.01; | *(fixed lot) | double | MA2_1; | *(previous value) | |||
| extern int | slippage = 0; | int | orderBuy; | *(1= present order Buy) | ||||
| int | orderSell; | *(1= present order Sell) | ||||||
| int | init ( ) | |||||||
| { | ||||||||
| } | ||||||||
| int | start ( ) | |||||||
| { | ||||||||
| orderBuy | =0; | |||||||
| orderSell | =0; | |||||||
| double | price; | |||||||
| int | openOrders=0; | |||||||
| int | total=OrdersTotal ( ); | |||||||
| for | (int i=total-1; | i>=0; | i--) | |||||
| { | ||||||||
| if | (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) | ==true) | ||||||
| { | ||||||||
| if | (OrderType( ) | ==OP_BUY) | ||||||
| { | ||||||||
| orderBuy | =1; | |||||||
| if | (CrossPositionClose( ) | ==1) | ||||||
| { | ||||||||
| price | =MarketInfo(Symbol( ),MODE_BID); | |||||||
| OrderClose | (OrderTicket( ), | OrderLots( ), | price, | slippage, | CLR_NONE); | |||
| } | ||||||||
| } | ||||||||
| (OrderType( ) | ==OP_SELL) | |||||||
| { | ||||||||
| orderSell | =1; | |||||||
| if | (CrossPositionClose( ) | ==2 | ||||||
| { | ||||||||
| price | =MarketInfo(Symbol( ),MODE_ASK); | |||||||
| OrderClose | (OrderTicket( ), | OrderLots( ), | price, | slippage, | CLR_NONE); | |||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| New_Bar | =0; | |||||||
| if | (Time_0 != Time[0]) | |||||||
| { | ||||||||
| New_Bar | =1; | |||||||
| Time_0 | = Time[0]; | |||||||
| } | ||||||||
| MA1_0 | =iMA | (NULL, | 0, | MA1_Period, | MA1_Shift, | MAMethod(MA1_Method), | MAPrice(MA1_Price), | 0); |
| MA1_1 | =iMA | (NULL, | 0, | MA1_Period, | MA1_Shift, | MAMethod(MA1_Method), | MAPrice(MA1_Price), | 1); |
| MA2_0 | =iMA | (NULL, | 0, | MA2_Period, | MA2_Shift, | MAMethod(MA2_Method), | MAPrice(MA2_Price), | 0); |
| MA2_1 | =iMA | (NULL, | 0, | MA2_Period, | MA2_Shift, | MAMethod(MA2_Method), | MAPrice(MA2_Price), | 1); |
| if | (CrossPositionOpen( ) | ==1 | && | New_Bar | ==1) | |||
| { | ||||||||
| OpenBuy( ); | ||||||||
| } | ||||||||
| if | (CrossPositionOpen( ) | ==2 | && | New_Bar | ==1) | |||
| { | ||||||||
| OpenSell( ); | ||||||||
| } | ||||||||
| return; | ||||||||
| } | ||||||||
| int | CrossPositionOpen( ) | |||||||
| { | ||||||||
| PosOpen | =0; | |||||||
| if | ((MA1_1<=MA2_0 && MA1_0>MA2_0) | || | (MA1_1 |
|||||
| { | ||||||||
| PosOpen | =1; | |||||||
| } | ||||||||
| if | ((MA1_1>=MA2_0 && MA1_0 less MA2_0) | || | (MA1_1>MA2_0 && MA1_0 less or=MA2_0)) | |||||
| { | ||||||||
| PosOpen | =2; | |||||||
| } | ||||||||
| return | ||||||||
| (PosOpen); | ||||||||
| } | ||||||||
| int | CrossPositionClose( ) | |||||||
| { | ||||||||
| PosClose | =0; | |||||||
| if | ((MA1_1>=MA2_0 && MA1_0 less MA2_0) | || | (MA1_1>MA2_0 && MA1_0 less or=MA2_0)) | |||||
| { | ||||||||
| PosClose | =1; | |||||||
| } | ||||||||
| if | ((MA1_1<=MA2_0 && MA1_0>MA2_0) | || | (MA1_1 less MA2_0 && MA1_0>=MA2_0)) | |||||
| { | ||||||||
| PosClose | =2; | |||||||
| } | ||||||||
| return | (PosClose); | |||||||
| } | ||||||||
| int | OpenBuy( ) | |||||||
| { | ||||||||
| if | (total | ==1) | ||||||
| { | ||||||||
| OrderSelect | (0, SELECT_BY_POS,MODE_TRADES); | |||||||
| if | (OrderType( ) | ==OP_BUY) | return; | |||||
| { | ||||||||
| OrderSend | (Symbol( ), | OP_BUY, | Lot, | Ask, | slippage,0,0, | "Buy: MA_cross_Method_PriceMode", | 1, 0, | CLR_NONE); |
| return; | ||||||||
| } | ||||||||
| int | OpenSell ( ) | |||||||
| { | ||||||||
| if | (total | ==1) | ||||||
| { | ||||||||
| OrderSelect | (0, SELECT_BY_POS,MODE_TRADES); | |||||||
| if | (OrderType( ) | ==OP_SELL) | return; | |||||
| } | ||||||||
| OrderSend | (Symbol( ), | OP_SELL, | Lot, | Bid, | slippage, 0, 0, | "Sell: MA_cross_Method_PriceMode", | 2, 0, | CLR_NONE); |
| return; | ||||||||
| } | ||||||||
| int | MAMethod | (int MA_Method) | ||||||
| { | ||||||||
| switch | (MA_Method) | |||||||
| { | ||||||||
| case | 0: | return(0); | ||||||
| case | 1: | return(1); | ||||||
| case | 2: | return(2); | ||||||
| case | 3: | return(3); | ||||||
| } | ||||||||
| int | MAPrice | (int MA_Price) | ||||||
| { | ||||||||
| switch | (MA_Price) | |||||||
| { | ||||||||
| case | 0: | return | (PRICE_CLOSE); | |||||
| case | 1: | return | (PRICE_OPEN); | |||||
| case | 2: | return | (PRICE_HIGH); | |||||
| case | 3: | return | (PRICE_LOW); | |||||
| case | 4: | return | (PRICE_MEDIAN); | |||||
| case | 5: | return | (PRICE_TYPICAL); | |||||
| case | 6: | return | (PRICE_WEIGHTED); | |||||
| } | ||||||||
| } | ||||||||
| BONUM | ||||||||
| extern int | StartHour | = 9; | ||||||
| extern int | Takeprofit | = 40; | ||||||
| extern int | StopLoss | = 40; | ||||||
| extern double | Lots | = 0.01; | ||||||
| Void | OnTick( ) | |||||||
| { | ||||||||
| static bool | IsFirstTick | = true; | ||||||
| static int | ticket | = 0; | ||||||
| if | (Hour( ) | == StartHour) | ||||||
| { | ||||||||
| if | (IsFirstTick | = true) | ||||||
| { | ||||||||
| IsFirstTick | = false; | |||||||
| if | (Open [0] | < Open [StartHour]) | ||||||
| { | ||||||||
| ticket | = OrderSend | (Symbol( ), | OP_BUY, | Lots, | Ask, 3, | Bid-StopLoss*Point, | Bid+Takeprofit*Point, | "Set by Bonum"); |
| if | (ticket < 0) | |||||||
| { | ||||||||
| Alert | ("Error Sending Order!"); | |||||||
| } | ||||||||
| } | ||||||||
| else | ||||||||
| { | ||||||||
| ticket | = OrderSend | (Symbol( ), | OP_SELL, | Lots, | Bid, 3, | Ask+StopLoss*Point, | Ask-Takeprofit*Point, | "Set by Bonum"); |
| if | (ticket < 0) | |||||||
| { | ||||||||
| Alert | ("Error Sending Order!"); | |||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| else | ||||||||
| } | ||||||||
| IsFirstTick | = true; | |||||||
| } | ||||||||
| } |
| extern int | ||||
| extern double | ||||
| bool |
Това също е параграф.