[r4stl1n] 5 minute Standard Deviation Scalping Bot Redux
stableDescription
Redux
This is a bot created to mimic the strategy suggested here:
https://www.forexstrategiesresources.com/scalping-forex-strategies/8-the-5-minute-standard-deviation-scalp/
It is not complete however there is some room for you to implement the take profit and stop loss should be simple enough have fun!
Note you will need the following command in order to use this bot:
https://www.haasscripts.com/t/simple-standard-deviation-command/
HaasScript
-- [r4stl1n] 5 minute standard deviation scalping Trading System
--
-- This bot is part of my bored and programming series where i pick different public forex strategies
-- and implement them into the haasscripts format to be used as examples.
--
-- This is a starting version of the strategy expand it to add the stop loss and take profit
-- Source: https://www.forexstrategiesresources.com/scalping-forex-strategies/8-the-5-minute-standard-deviation-scalp/
--------------------------------
-- You are on your own with this script
--------------------------------
-- ~Bored and programming series~
-- Some stolen convience functions from pshai
HideOrderSettings()
local isSpot = MarketType() == SpotTrading
local long_entry_cmd = isSpot and PlaceBuyOrder or PlaceGoLongOrder
local long_exit_cmd = isSpot and PlaceSellOrder or PlaceExitLongOrder
local short_entry_cmd = isSpot and PlaceSellOrder or PlaceGoShortOrder
local short_exit_cmd = isSpot and PlaceBuyOrder or PlaceExitShortOrder
-- Start of the code
local currentPrice = CurrentPrice()
local closePrices = ClosePrices()
local currentPosition = GetPositionDirection()
local orderId = Load('orderId', '') -- order id for the ideal exit
local maType1 = InputMaTypes('MA Type', EmaType, '', 'MA Types')
local maLength = Input('Ma Internval', 10, '', 'Period Lengths')
local ma = MA(closePrices, maLength, maType1)
local maStDev = CC_GetSTDev(ma)
local upper = Add(ma, maStDev)
local lower = Sub(ma, maStDev)
-- The current fee for market orders
SetFee(0.025)
-- Plot some pretty bands
Plot(0, 'Upper', upper)
Plot(0, 'MA', ma)
Plot(0, 'Lower', lower)
local goLong = currentPrice.close < lower
local goShort = currentPrice.close > upper
if goLong and currentPosition != PositionLong
then
if currentPosition == PositionShort
then
short_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
long_entry_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
if goShort and currentPosition != PositionShort
then
if currentPosition == PositionLong
then
long_exit_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Long'})
end
short_entry_cmd(currentPrice.close, TradeAmount(), {type=MarketOrderType, note='Short'})
end
-- save
Save('orderId', orderId)
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!