Simple Martingale Long and Short Position Increase Ratio Modification
!!!!!!!Friendly reminder: this strategy is for learning purposes only; actual trading will certainly result in liquidation!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Simple Martingale The principle is to…
!!!!!!!Friendly reminder: this strategy is for learning purposes only; actual trading will certainly result in liquidation!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Simple Martingale The principle is to double after losing until the desired profit is achieved As it is for backtesting, all orders are market orders, not run in live trading!!
Parameters
| Name | Default | What it controls |
|---|---|---|
| LongAmount | 150 | Initial long order quantity |
| ShortAmount | 100 | Initial short order quantity |
| MarginLevel | 50 | Set leverage |
| profit | 0.5 | Expected profit for long position |
| profits | 0.4 | Expected profit for short position |
| longbet | 1.1 | Turn on multiple magnifications |
| shortbet | true | Opening ratio |
| SetContractType | swap | Perpetual Contract |
| short | true | go short |
| long | false | go long |
| StopProfit | 5 | Take profit percentage |
| StopLoss | 6 | Stop Loss Percentage |
Source JavaScript
/*backtest
start: 2017-06-26 00:00:00
end: 2022-02-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
var m =LongAmount //Initial Order Quantity
var n = ShortAmount //Initial Order Quantity
var MarginLevel1 =MarginLevel //Contract Leverage
var SetContractType1=SetContractType // Contract Type
var longprofit = profit //Expected return, long positions must not be less than the fee
var shortprofits = profits//Expected return, short positions must not be less than the fee
var longbet1 =longbet //Turn on multiple magnifications
var shortbet2=shortbet //Opening ratio
StopProfit /=StopProfit ;
StopLoss /=StopLoss ;
//Get random number
function sum(m, n) {
var num = Math.floor(Math.random() * (m - n) + n);
return num;
}
function main(){
while(true){
LogProfit(exchange.GetAccount().Balance)
Sleep(2000)
}
}
function main() {
exchange.SetContractType(SetContractType1)
exchange.SetMarginLevel(MarginLevel1)
var position = []
while (true) {
position = exchange.GetPosition()
if (position.length == 0) {
//Get random number0,1As direction
var redom = sum(2, 0)
Log(redom)
redom=0==short //go short
if (redom == 0) {
n=ShortAmount
exchange.SetDirection("sell")
exchange.Sell(-1, n, "open short")
}
redom=1==long //go long
if (redom == 1) {
m=LongAmount
exchange.SetDirection("buy")
exchange.Buy(-1, m, "open long")
}
}
if (position.length > 0) {
if (position[0].Type == 0) {
//Long profit greater than expected
if (position[0].Profit >profit) {
exchange.SetDirection("closebuy")
exchange.Sell(-1, position[0].Amount)
let redom = Math.random()
if (redom < 0.5) {
m=LongAmount
exchange.SetDirection("buy")
exchange.Buy(-1, m, "Close long and open long positions")
}
}
//If long position negative profit exceeds the margin, then add position
if (position[0].Profit <position[0].Margin * -1) {
longbet1=longbet
m=m*longbet
exchange.SetDirection("buy")
exchange.Buy(-1, position[0].Amount=m)
}
}
//Short profit greater than expected
if (position[0].Type == 1) {
if (position[0].Profit > profits) {
exchange.SetDirection("closesell")
exchange.Buy(-1, position[0].Amount)
let redom = Math.random()
if (redom > 0.5) {
n=ShortAmount
exchange.SetDirection("sell")
exchange.Sell(-1, n, "Open a short position to offset a short")
}
}
//If short position negative profit exceeds the margin, then add position
if (position[0].Profit <position[0].Margin * -1 ) {
shortbet2=shortbet
n=n*shortbet
exchange.SetDirection("sell")
exchange.Sell(-1, position[0].Amount=n)
}
}
Sleep(60000)
}
}
}
Published by Zer3192 on the FMZ strategy square · last modified 2022-06-19. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Simple-Martingale-Long-and-Short-Position-Increase-Ratio-Modification.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- CTA Strategy Commodity Futures Simple MartingaleJavaScript · Martingale · 1d
- Fibonacci Sequence StrategyJavaScript · Martingale · 1d
- MartinGale Strategy1JavaScript · Martingale
- Random Number Martingale StrategyJavaScript · Martingale
- Simple Martingale BTC Contract Modify Add Position MultiplierJavaScript · Martingale · 1d
- Binance Multi Trading Pairs Spot Used for Market LiquidationJavaScript · Martingale