How can i place multiple orders in a single bar while in playback mode?
IOG = true;
position limits = 100;
properties/entries = allow any entry from this strategy (500) times per bar.
current MC version = 14.10
For testing im placing a trade at bar open then trying to place a trade every 10 points up from the opening trade. But so far ive only been able to place the first trade and that's it..
Is this a "you need to upgrade to mc 15 to be able to do this" thing ?
Multiple positions on single bar while in playback question
- Mark Brown
- Posts: 203
- Joined: Nov 29 2016
- Has thanked: 152 times
- Been thanked: 26 times
Here is the code that buys on the open of the bar and subsequently buys every 10 points thereafter. This will involve tracking the last purchase price and ensuring that another purchase is made only when the price has moved 10 points from the last purchase price.
Explanation:
Variables:
lastPurchasePrice: Keeps track of the price at which the last purchase was made.
initialPurchaseDone: Boolean variable to track whether the initial purchase has been done.
Initial Purchase:
The system buys at the open of the bar if initialPurchaseDone is false.
After the initial purchase, lastPurchasePrice is set to the open price of the bar, and initialPurchaseDone is set to true.
Subsequent Purchases:
The system checks if the price has moved 10 points from the lastPurchasePrice.
If it has, it buys at the current market price and updates lastPurchasePrice to the current price.
Risk Management:
Sets a profit target and stop loss as per the input values profitTarget and stopLoss.
This code ensures that after an initial purchase on the open of the bar, subsequent purchases are made every 10 points thereafter.
Code: Select all
// Declare variables to track the last purchase price and initial purchase
vars:
lastPurchasePrice(0),
initialPurchaseDone(false);
// Risk Management Inputs
inputs:
profitTarget(5), // Profit target in points
stopLoss(10); // Stop loss in points
// Check if initial purchase has not been done
If not initialPurchaseDone Then
Begin
// Buy on the open of the bar
buy next bar at open;
// Set the last purchase price to the open price of the bar
lastPurchasePrice = open;
// Set initial purchase status to done
initialPurchaseDone = true;
End;
// Check if the price has moved 10 points from the last purchase price
If initialPurchaseDone and c >= lastPurchasePrice + 10 Then
Begin
// Buy at the current price
buy next bar at market;
// Update the last purchase price to the current price
lastPurchasePrice = c;
End;
// Risk Management Commands
// Set a profit target to automatically secure profits when the price reaches the specified points in your favor
setprofittarget_pt(profitTarget);
// Set a stop loss to limit potential losses to the specified points when the price moves unfavorably
setstoploss_pt(stopLoss);
Explanation:
Variables:
lastPurchasePrice: Keeps track of the price at which the last purchase was made.
initialPurchaseDone: Boolean variable to track whether the initial purchase has been done.
Initial Purchase:
The system buys at the open of the bar if initialPurchaseDone is false.
After the initial purchase, lastPurchasePrice is set to the open price of the bar, and initialPurchaseDone is set to true.
Subsequent Purchases:
The system checks if the price has moved 10 points from the lastPurchasePrice.
If it has, it buys at the current market price and updates lastPurchasePrice to the current price.
Risk Management:
Sets a profit target and stop loss as per the input values profitTarget and stopLoss.
This code ensures that after an initial purchase on the open of the bar, subsequent purchases are made every 10 points thereafter.
Hi Mark... Thanks for your code there... so good new and bad news lol... Bad news is I tried your code and it didnt quite work for me (though i 100% appreciate it)... But the good news is i realized in your code you used "next bar at open" ... I changed that in my code, And that worked..
Thankyou![Smile :)](./images/smilies/icon_smile.gif)
Thankyou
![Smile :)](./images/smilies/icon_smile.gif)