| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
|||
|
MaOnArray
Hi,
it would like to go long if the CCI goes above it's 14 sma, and go short when it goes below it's 14 sma. The CCI's sma is generated by the MaOnArray of the CCI of course. This is my piece of code: double a,b; bla, bla, bla... int start() { a= iCCI(NULL, 0, 14,PRICE_WEIGHTED,0); b=iMAOnArray(a,0,14,0,MODE_SMA,0); // check for long position (BUY) possibility if(NewBar1()==true && a>b) { bla, bla, bla... // check for short position (SELL) possibility if(NewBar2()==true && a<b) { bla, bla, bla... There is a problem however (it's pictured below) - so is there something that's missing in the code? and how can this problem be solved? Problem is below: |
|
|||
|
MaOnArray
Jane,
First, you need to control how many trades open. I suggest adding if (OrdersTotal()==0) { before entry filters, or maybe <= 1, for 2 orders allowed. Or if you want more than two trades at a time: for (int i = OrdersTotal() - 1; i >= 0;i--) (Study most EAs for this one.) I don't think you have given enough data for one to solve it, but I have a couple more suggestions. It is not clear what NewBar1() does and how. Make sure your global variables are re-set as needed after an order is opened (or closed, if applicable). I write a line for each necessary variable after the open order line. Good hunting! Big Be |
|
|||
|
Two Stops Question
I need to know how to change the Stop for HALF of my open order. My understanding is that this means opening two orders, for example .2 lots and .2 lots.
My EA bases the number of lots on a Money Management calculation. After the stop for one order is changed (based on a price level being reached) then I would let my exit code close both orders, unless their (now different) stops are hit. The other order retains its original stop or possibly moves it up to Break Even. If the initial quantity of lots (from the MM function) Is odd, instead of rounding down for an odd number of lots or tenth lots, I would like to split them unevenly between the two orders. I believe this involves Magic Numbers, and a couple lines of code here and there. Maybe there is an EA with all this that I could copy from. Thanks for any help. Big Be |
|
|||
|
Quote:
|
|
|||
|
Re: Two Stops Question
Quote:
Big Be |
|
|||
|
Help with EA errors
Hi, I need help with the following EA. This is my frist EA so be (gentle) please.
When I compile the file I get two warning (s) that both read: 'TotalOpenOpenOrders'-expression on global scope not allowed This warning come after the word Max in the file. // init variable when the expert advisor first starts running if (init_variables == true) { PreviousBar = Time[0]; // record the current candle/bar open time // place code here that you only want to run one Time init_variables = false; // change to false so we only init // variable once } // perform analysis and open orders on new candle/Bars if(NewBar() == true) { // only perform analysis and close order if we only have one order Open if(TotalOpenOrders() == Total_Open_Orders && SelectTheOrder() == True) { if(OrderType() == OP_BUY && TrendDetection() == BEAR) { OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Order_Arrow_Color); } if(OrderType() == OP_SELL && TrendDetection() == BULL) { OrderClose(OrderTicket(),OrderLots(),Ask,Slippage, Order_Arrow_Color); } } // only perform analysis and open new order if we have not reached // our Total_Open_Orders Max if(TotalOpenOrders() < Total_Open_Orders) { // open buy if(TrendDetection() == BULL) { // open Order OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Stop_L oss*Point,Take_Profit *Point,Order_Comment,Magic,0,Order_Arrow_Color); } //open sell if(TrendDetection() == BEAR) { // open Order OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Stop_ Loss*Point,Take_Profit *Point,Order_Comment,Magic,0,Order_Arrow_Color); } } // when back testing only display chart info every // candle/bar sowe do not slow down back tests if(IsTesting() == true) { Display_Info(); } } // when not back testing display chart info every tick if(IsTesting() == false) { Display_Info(); } return(0); } |
![]() |
| Bookmarks |
| Tags |
| candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
|
||||
| Posted By | For | Type | Date | |
| Need an experienced programmer? - Page 2 | Post #0 | Refback | 09-24-2008 07:24 AM | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to code this? | iscuba11 | Metatrader 4 mql 4 - Development course | 1 | 08-03-2007 05:22 PM |