Help editing code to execute only if spread is 0 or 1
Results 1 to 9 of 9

Thread: Help editing code to execute only if spread is 0 or 1

  1. #1
    Hello. Below attached is script.

    I've attempted to edit the script to only execute hedging orders, only if the spread is zero or one.

    I got this code by searching, but could not apply it.

    Inserted Code extern dual MaxSpread = 4; Spread = MarketInfo(Symbol(), MODE_SPREAD); should (Spread gt;= MaxSpread) return(0);
    Please watch in the script, and tell me what to do, or if you can edit/code the script using it, I'd be quite grateful.

    Thanks.
    https://forexintuitive.com/attachmen...1212398970.ex4
    https://forexintuitive.com/attachmen...1023817129.mq4

  2. #2
    Quote Originally Posted by ;
    Not that this is much help but max should most likely be 1 (for 1 or 0 ), don't forget Spread ought to be described as double. You have to place the above as a state that tests somewhere ahead of your open commerce function. Aside from that Im unable to make much sense of this script (as'm not a professional coder). I might take a look at it later when I've more time. Where did you get this code and what was it originally suppose to do? Does this work or do something how you initially found it? Can you just want code that opens 2 opposite trades in the...
    Hello, thank you so much for taking this into account and trying to help. I see you have clearly an notion of what I want. Besides the script is an MT4 script, which should I drag onto chart, it places 2 orders in reverse directions at precisely the exact same time. It is a hedging egy that I'm practicing.

    I've tried to set your code in the script, but couldn't get it to work.

    Inserted Code'Send Buy Sell.mq4' Send Buy Sell.mq4 1 1'Maxspread' - undeclared identifier Send Buy Sell.mq4 36 13 1 error(s), 0 warning(s) 2
    Please help. Thank you, brother.

  3. #3
    It was a capitalization mistake. I shifted'Maxspread' to'MaxSpread'. No mistakes, but the script is being weird.

    I'm using this on Finpro-trading broker, so to check the script, their demo account server is: TurnkeyFX-Demo
    Can be made using MT4. Make sure that you choose'ECN', and USD account.

    I attempted to do it in this way, but:

    Inserted Code // ------------------------------------------------------------------ //| send_buysell. mq4 | //| Copyright © 2004, MetaQuotes Software Corp.. | //| http://www.metaquotes.net/ | // ------------------------------------------------------------------ #property copyright Copyright © 2004, MetaQuotes Software Corp. #property Hyperlink http://www.metaquotes.net/ #property show_inputs //-- Parametres Externes extern dual BuyLots = 0.01; extern int BuyStopLoss = 10; extern int BuyTakeProfit = 15; extern dual SellLots = 0.01; extern int SellStopLoss = 10; extern int SellTakeProfit = 15; extern dual MaxSpread = 1; // ------------------------------------------------------------------ //| script ship pending order with terminal data | // ------------------------------------------------------------------ int start() int ticket,expiry; double point; //-- point=MarketInfo(Symbol(),MODE_POINT); expiration=CurTime() PERIOD_D1*60; //-- double Spread = MarketInfo(Symbol(), MODE_SPREAD); //-- if(Spread gt; MaxSpread) while(true) while (true) ticket=OrderSend(Symbol(),OP_SELL,SellLots,Bid,0,B id SellStopLoss*Point,Bid-SellTakeProfit*Point,SELL,NULL,0,Red); if(ticketlt;=0) Publish (Error =,GetLastError()); else Print(ticket =,ticket); break; //-- 10 minutes wait Sleep(10000); while(true) while (true) ticket=OrderSend(Symbol(),OP_BUY,BuyLots,Ask,0,Ask-BuyStopLoss*Point,Ask BuyTakeProfit*Point,BUY,NULL,0,Lime); if(ticketlt;=0) Publish (Error =,GetLastError()); else Print(ticket =,ticket); break; //-- 10 minutes wait Sleep(10000); //-- return(0); // ------------------------------------------------------------------
    It is spamming the orders, using only'SELL' orders, meaning it disregards what the script needs to actually which is to set only 2 orders in opposite direction if the spread is 1 or 0.

    In the event you are debugging the script, try out the pairs AUDUSD, and EURUSD, they've lowest spreads.

    Thank you.

  4. #4
    Quote Originally Posted by ;
    Hello. Below attached is script. I've attempted to edit the script to only execute hedging orderswhen the spread is one or zero. I got this code but couldn't apply it. Extern double MaxSpread = 4; Spread = MarketInfo(Symbol(), MODE_SPREAD); if(Spread gt;= MaxSpread) return(0); Please see into the script, and tell me what to do, or if you can edit/code the script with it, I'd be really grateful. Thanks. file file
    I'm here to warn you not to use this script if you don't just feel the strong urge to provide your broker a wonderful bonus. All this script does is open and immediately close a situation having the reverse order. It is like saying, hey mister broker guy, here is some risk-free commission money for ya. You're better off just not investing in any way.

  5. #5
    Try tinkering with this. I combined it while loop. Remember always use this on demonion first. I'm unable to test any of this code on my demo account, it doesnt run scripts for some reason. This is good for experimentation; but in the event you're attempting to construct one those sophistied grid trading hedge egies then this is over both of our heads, as this is basically starting from scratch. While I attempt a new bot egy I begin with a bot code that currently works. I utilize mql4-reference (in the help menu) and also the bot code as a skeleton and create small modifiions at one time. I recommend that for men and women that aren't good coders.

    PS: I think you will need another condition aside from disperse being less than 1. This might account for why it is spamming with orders. Provided that disperse is 1 it might keep opening trades, but Im not sure, have to go. Something should test whether both trades are opened subsequently not open any more possibly. Edited again to add totaltrades condition. Your broker will give you an unfriendly telephone call if the bot uses too many resources aka spamming.

    Inserted Code int start() int ticket,ticket2, expiration; //added another ticket variable double point; stage = MarketInfo(Symbol(),MODE_POINT); expiration=CurTime() PERIOD_D1*60; extern double MaxSpread = 1; double Distribute = MarketInfo(Symbol(), MODE_SPREAD); int totaltrades =0; while(true) //mixed into 1 while loop (totaltrades==2) ) return(0); ticket =OrderSend(Symbol(),OP_SELL,SellLots,Bid,0,Bid SellStopLoss*Point,Bid-SellTakeProfit,0 Stage,SELL,NULL,0,Red); ticket2 =OrderSend(Symbol(),OP_BUY,BuyLots,Ask,0,Ask-BuyStopLoss*Stage,Ask BuyTakeProfit*Stage,BUY,NULL,0,Lime); totaltrades=two; if(ticketlt;=0 /* while(true) ticket2 =OrderSend(Symbol(),OP_BUY,BuyLots,Ask,0,Ask-BuyStopLoss*Stage,Ask BuyTakeProfit*Stage,BUY,NULL,0,Lime); if(ticketlt;=0) Print(Error =,GetLastError()); else Print(ticket =,ticket); break; //-- 10 seconds wait Sleep(10000); */ return(0);

  6. #6
    Quote Originally Posted by ;
    Attempt tinkering with it. I combined it while loop. Remember always use this on demonion first. I am not able to check any of this code in my demo account, it doesnt run scripts for some reason. That is good for experimentation; however in the event you're attempting to construct one those sophistied grid trading hedge egies then that is over both of our heads, as it is basically starting from scratch. While I try a new bot egy I start with a bot code that already works. I utilize mql4-reference (in the help menu) as well as the bot code as a skeleton and make...
    Inserted Code'Send Buy Sell.mq4' Send Buy Sell.mq4 1 'extern' - unexpected token Send Buy Sell.mq4 29 4 1 error(s), 0 warning(s) 2 1
    I get this. .

  7. #7
    I moved the'extern' towards the top.

    Not sure what's going wrong. The initial script is attached at the first post.

    It currently opens two orders, in only half a while, it closes one particular order, then . Maybe it's detecting that disperse is not any longer 1, therefore it closes it. It should not behave in this way.

    It must only work just if the spread is 1, and that will be all. Rest it should work normally.

    So far this is exactly what it looks like now:

    Inserted Code // ------------------------------------------------------------------ //| send_buysell. mq4 | //| Copyright © 2004, MetaQuotes Software Corp.. | //| http://www.metaquotes.net/ | //p ------------------------------------------------------------------ #property copyright Copyright © 2004, MetaQuotes Software Corp. #property Hyperlink http://www.metaquotes.net/ #property show_inputs //-- Parametres Externes extern dual BuyLots = 0.01; extern int BuyStopLoss = 10; extern int BuyTakeProfit = 15; extern dual SellLots = 0.01; extern int SellStopLoss = 10; extern int SellTakeProfit = 15; extern double MaxSpread = 1; // ------------------------------------------------------------------ //| script send pending order with terminal data | // ------------------------------------------------------------------ int start() int ticket,ticket2, expiration; //added another ticket variable double point; point= MarketInfo(Symbol(),MODE_POINT); expiration=CurTime() PERIOD_D1*60; double Spread = MarketInfo(Symbol(), MODE_SPREAD); int totaltrades =0; while(true) //mixed to 1 while loop /* while(true) ticket2 =OrderSend(Symbol(),OP_BUY,BuyLots,Ask,0,Ask-BuyStopLoss*Stage,Ask BuyTakeProfit*Stage,BUY,NULL,0,Lime); if(ticketlt;=0) Publish (Error =,GetLastError()); else Print(ticket =,ticket); break; //-- 10 minutes wait Sleep(10000); */ return(0); // ------------------------------------------------------------------
    Thanks, champ.

  8. #8
    Guys, guys... let's think about this logically. What exactly are you hoping to achieve here? Why does spread matter in the context of this program?

    Let us break it down:You open a 0.01 lot market place [in]. You instantly close that position using a 0.01 lot buy order [out] (0.00 internet position size) Your position is currently ified yet you're on the hook for commissions, swaps, and spread (buy-price - sell-price). I know exactly what the aim is... you wish to trade a channel range, but this is actually the laziest and most profit wasting way to execute such a egy. Why don't you use limit orders instead and not waste your money?

  9. #9
    Not that this is much assistance but maximum should probably be 1 (for 0 or 1), do not forget Spread should be defined as double. You have to place the aforementioned as a state that tests someplace before your open commerce purpose. Other than that Im unable to make much sense of the script (as Im not an expert coder). I might take a look at it later when I have more time. Where did you get this code and what was it originally suppose to do? Does it work or do anything how you originally found it? Do you just want code that opens two opposite trades at the exact same time when spread is less than 1?

    Something similar to this possibly?
    Extern double MaxSpread = 1;
    double Distribute = MarketInfo(Symbol(), MODE_SPREAD);
    while (true)
    if(Spread gt; Maxspread) return(0);
    ticket=OrderSend(Symbol(),OP_SELL,SellLots,Bid,0,B id SellStopLoss*Point,Bid-SellTakeProfit*Point,SELL,NULL,0,Red);
    etc etc....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information